HardCoreMore Posted October 20, 2010 Share Posted October 20, 2010 Hello, I am interested in how the php can recognise a certain session when everytime i start session new id is created. For example i made this small script: session_start(); if( isset( $_SESSION['test'] ) ) { echo "test is set"; } else { $_SESSION['test'] = 'test'; echo "test is not set"; } My browser is closed. All files from /tmp folder where php default sessions files are stored in wamp are deleted. So i start the browser and it of course echoes "test is not set", then i check the folder and new session file is created. I then refresh the page and it normally echoes "test is set" but no new session files are created in /tmp folder. So now i close the browser and start it again. New file is created in /tmp although i used same browser. Now this new file has a different name than one previously created. So this time again it says "test it not set" and when i refresh the page it says "test is set" so my question is what logic is used by php to determine from which session file in /tmp folder to load session on page refresh when it creates a new id every time session is started ( browser opened ) even though the browser and ip are same. Thanks Link to comment https://forums.phpfreaks.com/topic/216358-php-session-id/ Share on other sites More sharing options...
rwwd Posted October 20, 2010 Share Posted October 20, 2010 In your cookie register dialogue from your browser, there is something called PHPSESSID which is how php recognises the sessions and how it can recognise what is running as all the needed information is stored in that cookie, as $_SESSION is 'technically' a $_COOKIE, ie it behaves the same way and gets stored in the same manor, difference being that you can set the time a cookie is set for directly from the setcookie(), but with sessions, there is a default value, which I think is around 24 mins, though this can be manipulated. At least that is how I have come to understand it to function over the years... Rw Link to comment https://forums.phpfreaks.com/topic/216358-php-session-id/#findComment-1124312 Share on other sites More sharing options...
HardCoreMore Posted October 20, 2010 Author Share Posted October 20, 2010 Hey, thanks for your reply. Now its all clear. I was confused because i didn't know that by using php session you actually utilize cookies as well. But how the browser is sending that id automatically on every request? So there are no sessions systems without writing data on the client excpet with using continous connection which is not the case here? Thanks again for your reply! Link to comment https://forums.phpfreaks.com/topic/216358-php-session-id/#findComment-1124319 Share on other sites More sharing options...
rwwd Posted October 20, 2010 Share Posted October 20, 2010 As I said, cookies and sessions technically work off the same principle, clear PHPSESSID from the list to see what happens. Rw Link to comment https://forums.phpfreaks.com/topic/216358-php-session-id/#findComment-1124361 Share on other sites More sharing options...
HardCoreMore Posted October 20, 2010 Author Share Posted October 20, 2010 Hey thanks again for reply. The thing is that PHPSESSID is a cookie and browser automatically sends all cookies in headers. Link to comment https://forums.phpfreaks.com/topic/216358-php-session-id/#findComment-1124367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.