I have this code. What I'm trying to do is if a cookie exsits then the session should equal the cookie. If a cookie does not exsists and a session exsists then leave the session as it was. If a cookie does not exsists and a session doesn't exisit then set a cookie and create a session with the same value. What am I doing wrong with this code:
session_start();
if (!isset($_COOKIE['b'])) {
if (!isset($_SESSION['a'])) {
$RAND = rand(1,5);
$_SESSION['a'] = $RAND;
setcookie(b,$RAND,time()+60*60*24*30);
}
} else {
$_SESSION['a'] = $_COOKIE['b'];
}
It works fine if cookies are enabled but when they are disabled it keeps resettig the session variable.