I've built a registration page on a site that stores a unique id for a user when they register. That id is then stored in a database and set as a session variable and as a cookie and is used to register personal user preferences.
The reason I use both is that I don't really want to make people log in everytime they revisit the site. I use the session so that people who have cookies turned off can still benefit from the personalisation. The cookie is used so that when a user revisits the site, they don't have to log in again.
I then have a script that I call in every page that checks for the session variable and the cookie. I have been testing the script using
echo $_SESSION['usr']; and echo $_COOKIE['usr'];
and I get correct values for both. Unfortunately if I then close the browser, reopen it and visit the site, both the cookie and the session produce no values. Obviously, the session value should be blank, but the cookie should produce a value.
This is my 'global' cookie/session checker script:
<?php session_start();
// CHECK IF SESSION EXISTS.
if (!isset($_SESSION['usr'])) {
// IF NO, THEN CHECK FOR COOKIE
if (isset($_COOKIE['usr'])) {
// IF 'YES' THEN START SESSION
$_SESSION['usr'] = $_COOKIE['usr'];
}
// IF 'YES' THEN QUIT }
else {
// IF THE SESSION EXISTS, MAKE SURE [EMAIL PROTECTED] VALUE MATCHES THAT OF THE COOKIE
setcookie("usr", $_SESSION['usr'], mktime(21,00,0,12,31,2014),"/","bigbarn0.kbnet.net", 0);
// END
}
?>
If anyone can point out an error, please do!
Thanks, Matt
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php