0
votes

Book said, persistent cookie stay on client machine till it expires. session cookie will be gone after browser closed.

i tried it, like:

setcookie("name", "value");  // before any output

but after closing browser and restart, it is still there (from print_r($_COOKIE)).

i tried couple of different browsers like safari, chrome, firefox, it is all like that. only eclipse is different:)

so, are all current browsers not following that "rule" ? or there is some default time-out for a session cookie i am not aware of?

thanks.

EDIT:

I checked in firebug it said:

Name Value Domain Expires

name value localhost session

5
you'd have to check your particular cookie settings. YOUR particular php may be configured to set permanent session cookies. session cookies are supposed to be temporary ones, bu that's purely a convention. nothing says someone can't set permanent session cookies. - Marc B
Can you please add what you observe in the headers of that request network panel of those browsers? - try-catch-finally
To Marc B: thanks. in firebug, it said "session", so that means it is a session cookie. then the problem is when will the "session cookie" expire:) - totally

5 Answers

0
votes

Check your PHP settings for session cookie name, domain and path, and unset the cookie using the same values given to setcookie(). They can all be read with ini_get() and fed to variables.

The above advice assumes you're using PHP built-in session mechanism, ie. you don't use a framework with it's own, custom session library.

0
votes

What you set there is not a session cookie. After the page is loaded in the browser go check the cookies set from your server (localhost if it's local machine), you'll see a SESS_ID cookie which is set by the server and it goes when you close the browser

0
votes

What you are actually trying to set is a persistent cookie..A session cookie or simply session can be simply set by starting a session or storing a value in session like $_SESSION['name']=$value.

What you are doing is a persistent cookie it wont expire even if browser is closed. It expires only after the time set in cookie expires.

Like setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); it will set cookie info for 1 day..even if browser it closed..

You can set time and cookie info according to your needs... `

0
votes

That's because you're setting a cookie.

Sessions are not cookies. Cookies are not sessions.

http://www.tuxradar.com/practicalphp/10/1/0

Quoted from the first page:

Cookies can be set to a long lifespan, which means that data stored in a cookie can be stored for months if not years.

And sessions, via the page on sessions:

It is also important to note that sessions only last till the user closes their browser, whereas cookies can be configured to last longer.

0
votes

Thanks to everyone's response. It's my problem. i am working on macbook, i thought clicking the red cross will close the browser. but although browser is gone. on the very top of my screen, it is still safari menu bar. i have to click safari and quit it.

now, all my session cookies are gone after closing the browser:)