Jump to content

Php Session id?


HardCoreMore

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
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.