• A Great friend to the HardForum with a great kid that he is trying to get a scholorship to continue his schooling. Please give hime a vote! Only 24 hours left! Thanks.
    If you have an VOTE FOR KEENAN!

PHP/Cookie/Serialize help

BuisyBizz

Limp Gawd
Joined
Jun 17, 2002
Messages
445
I'm trying to add a remember me feature. Could someone tell me why this wont work?
in the Login sctipt:
Code:
$rand is the value from a random generator. (though i'm not using it right now for testing)
if(isset($_POST['remember']))
{	
	$rand = generateUniqID();
	$StoredCook = md5($rand);
	$cookie = serialize($_SESSION['username']);
	//$cookie = serialize(array($_SESSION['username'], $rand));
	setcookie("buisybizzLogin", $cookie, time()+60*60*24*100, "/");
	$db_object->query("UPDATE users SET cookie = '$StoredCook'
		WHERE username = '".$_SESSION['username']."'");
}

in a sctipt I created to test things:
Code:
if(isset($_COOKIE['buisybizzLogin']))
{
	echo "Cookie is set";
	echo "<br>";
	$Foo = $_COOKIE['buisybizzLogin'];
	$username = unserialize($_COOKIE['buisybizzLogin']);
	echo "test unserial uid from cook: $username";
	echo "<br>";
}
This prints nothing, printing the cookie gives me: s:9:\"buisybizz\";
WTF am i doing wrong. The reason I'm serializing is because i want to store the username and a random string in the cookie, then store the same string in my db, and compare them for remembered logins.

Edit: NVM, i got it. I was because the webserver adds slashes to the cookie value before it writes it, so all i needed to do was stripslashes() from the cookie value.
 
Back
Top