Jump to content

session_start() creates new session on page reload


Recommended Posts

The sessions on my server are being written but are not getting read

the following code used:

if (isset($_POST['submit'])) {
if(!isset($_SESSION['cheese'])) {
$_SESSION['cheese'] = 1;
} else {

session_start() creates new session on page reload meaning its not picking up the session. The above code displays no value.

php ini file looks like this for sessions:



Link to comment
Share on other sites

The code doesn't display anything, so what exactly makes you think that sessions aren't resumed?


Execute this script twice and show us each response:



echo 'Cookies:<br>';
echo '<br>';

echo 'Session:<br>';

$_SESSION['test-8165'] = 'test';

Also check the PHP error log.

Link to comment
Share on other sites

If you're navigating to other pages you need session_start() at the top of them too if you're going to access session data. Session start doesn't just start a new session, but allows you to access the variables in your server.



$_SESSION['hello'] = 'Hi, there!';

echo '<a href="show.php">Click Me!</a>';


echo $_SESSION['hello'];

When you load index you'll get a hello message set to hello index in $_SESSION. When you navigate to show.php you will see the message.

Edited by JeremyBenson11
Link to comment
Share on other sites

Are cookies disabled on your browser?  If so, enable them.  If not, try the following:

echo('session_name(): <pre>'.print_r(session_name(),1).'</pre>');
echo('session_id(): <pre>'.print_r(session_id(),1).'</pre>');
echo('session_get_cookie_params(): <pre>'.print_r(session_get_cookie_params(),1).'</pre>');
echo('$_COOKIE: <pre>'.print_r($_COOKIE,1).'</pre>');
echo('$_SESSION: <pre>'.print_r($_SESSION,1).'</pre>');
Link to comment
Share on other sites

the OP's symptom is most probably due to php not being able to send the session cookie to the browser. the session data file is still created in this instance.


does the OP have php's error_reporting set to E_ALL and display_errors set to ON in the php.ini on his development system so that php would report and display all the errors it detects, particularly a couple of warnings at the session_start() statement?

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.