I’m new to PHP and havn’t worked with sessions before, I have read up on it a bit and understand what they do and how i should be able to use them.
When I create my session however, it seems to create the session fine (code gets run and if I look into cookies I can see entries from my website)
I can also set $_SESSION values on the same page, but as soon as I enter a different page, the session is reset it seems.
Here’s my code:
$sessionid = md5(uniqid(microtime()) . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
ini_set('session.auto_start', 1);
ini_set('session.lifetime', 2678400);
ini_set('session.use_cookies', 1);
ini_set('session.cache_limiter', 'private_no_expire');
session_start($sessionid);
// Also tested that setting these doesn't give an error either
$_SESSION['Username'] = //Code to get username
$_SESSION['UserID'] = // Code to get userID
echo "<script language='Javascript'>";
echo "window.location='" . $forwardpage . "';";
echo '</script>';
exit();
Any help would be appereciated
The problem is that every time you load the script a new session id is created and sent to the client.
Skip the $sessionid variable and php will generate a sessionid for you and it will work.
So, use session_start() without $sessionid