setcookie problem
Posted: Thu May 20, 2004 2:02 am
Hi,
I'm trying to set a cookie if a user has opted to be remembered. Using:
But I've cleared the cookies on my PC, and its not doing anything. So, I've tried this to check whether or not its setting the cookie:
So, if the user wants to be remember, it will check to see if the cookie is being set. This works! This will set the cookie and stop on a blank screen saying "Cookie Set" And i can see it on my PC. Then, when i go to the next screen, the cookie is deleted and nothing is remember anymore... This is the only thing that "should" cause a problem on the forwarding page...
But I cant see how that should cause a problem. Also, I'm testing this on my pc, so the domain is localhost, but it doesnt change if i have in in the "Domain" section in the setcookie function. Any help would be great!
- Crimpage
I'm trying to set a cookie if a user has opted to be remembered. Using:
Code: Select all
<?php
if (isset($_POST['cookieitup'])) //Does the person want to be remember
{
setcookie(session_name(), session_id(), (time() + 60*60*24*367), '/', '', '0');
}
?>But I've cleared the cookies on my PC, and its not doing anything. So, I've tried this to check whether or not its setting the cookie:
Code: Select all
<?php
if (isset($_POST['cookieitup']))
{
if (setcookie(session_name(), session_id(), (time() + 60*60*24*367), '/', '', '0') == TRUE)
{
echo "Cookie Set";
exit();
} else
{
echo "Not Set";
exit();
}
} else
{
echo "sumthing wrong";
exit();
}
?>So, if the user wants to be remember, it will check to see if the cookie is being set. This works! This will set the cookie and stop on a blank screen saying "Cookie Set" And i can see it on my PC. Then, when i go to the next screen, the cookie is deleted and nothing is remember anymore... This is the only thing that "should" cause a problem on the forwarding page...
Code: Select all
<?php
if (isset($_COOKIE['PHPSESSID']))
{
session_id($_COOKIE['PHPSESSID']);
session_start();
} else
{
session_start();
}
?>But I cant see how that should cause a problem. Also, I'm testing this on my pc, so the domain is localhost, but it doesnt change if i have in in the "Domain" section in the setcookie function. Any help would be great!
- Crimpage