Search code examples
phpsessionsession-statesessionid

session changes on page refresh


Maybe I'm misunderstanding this, but I expect the following to return the same session id on page refresh;

<?php
session_start();
$ses_id = session_id();
echo $ses_id;
?>

Whenever I refresh the page, the session id updates to a new one. I'm running PHP on Windows 7 IIS. Client is iphone safari browser.

Initially I was trying to trace a problem with an AJAX call and session variables, but in troubleshooting I realised my calling page couldn't even retain it's own session during a page refresh - so I figure if I fix this, then at least I can start troubleshooting the AJAX issue, if it's still there.

What I've done;

PHP ini - confirmed sessions are enabled with the following settings (mostly default except for session.save_path which was "/tmp" and session.cookie_domain which was blank...

session.save_handler = files
session.save_path = "c:\windows\temp"
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain = .<mydomain.com>  --  <censored> :)

...


Solution

  • Thanks @Arpit for your oddly vague comment which nonetheless pointed me in the right direction :)

    Changed:
    iphone -> settings -> safari -> accept cookies -> Never

    to

    iphone -> settings -> safari -> accept cookies -> From Visited

    And now session stays the same.
    Not great for my app though; I have to ask users to change their safari settings.