Forum Moderators: coopster
<?phpsession_start();
if (!isset($_SESSION['id'])) {
$_SESSION['id']=session_id();;
}
else {
echo $_SESSION['id'];
}
?>
I'm running XAMPP PHP5 on WinXP SP2, testing with Firefox.
When I disable cookies, the code runs fine, but the session id is not being retained in the session variable 'id'. Also, a new session is being created in my /tmp every time I reload the page.
I want the script to store the sessionid in a session variable across pages, not a cookie!
Thanks,
Nick
[php.net...]
Note: When using session cookies, specifying an id for session_id() will always send a new cookie when session_start() is called, regardless if the current session id is identical to the one being set.
Try this out:
<?phpif(!isset($_SESSION)) session_start();
$_SESSION['id'] = strip_tags(SID);
echo $_SESSION['id'];
?>
Hope this helps
Regards
Michal
Try this:
test.php:
<?php
if(!isset($_SESSION)) session_start();if(isset($_SESSION['test']))
{
echo $_SESSION['test'];
}
else
{
$_SESSION['test'] = "Session is set and remembered, no matter the SID";
echo 'Session was not set. <a href="test.php">Click here</a> to refresh';
}
?>
After you click on the link, session should be set and remember the data.
Michal