Forum Moderators: coopster
$expire = time() + 60*60*24*30;
if($_POST['remember'])
{
setcookie("NITEFLIP_REMEMBER_USERNAME", $_POST['username'], $expire);
setcookie("NITEFLIP_REMEMBER_PASSWORD", $_POST['password'], $expire);
}
...and sure enough, when I look at the cookies in FireFox, they appear as I set them. Cool.
However, my problem is I can't seem to retrieve them. I put a tester php script at the top of my home page:
if(isset($_COOKIE['NITEFLIP_REMEMBER_USERNAME']))
{
echo "Username is set";
} ...but nothing is appearing. What am I doing wrong?
Thanks.
setcookiecode.php
if(isset($_POST['set'])){
$expire = time()+60*60*24*30;
$password = $_POST['password'];
$encoded = base64_encode(serialize($password));
setcookie("user", $_POST['user'], $expire);
setcookie("password", $encoded, $expire);
setcookie("set", $_POST['set'], $expire);
}
else
{
setcookie ("user", "", time() - 3600);
setcookie ("password", "", time() - 3600);
setcookie ("set", "", time() - 3600);
}
top.php
$user = $_COOKIE['user'];
$password = $_COOKIE['password'];
$password = unserialize(base64_decode($password));
echo "$user $password";
If you are setting them in a sub-directory and then trying to access them on the root they will not be available, and they will only be available on one version of the domain the way you are setting them, so if they are set at www.example.com/dir/ they will not be available at www.example.com or example.com/dir/.
Also, you said you're using FireFox, what domain and path does it say they're available for? Is that where you're trying to access them from?