visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: relationship between $_COOKIE and $_SESSION ??


By: Bernard France  Date: 31/12/2004 09:15:58  English French  Points: 40 Status: Answered
Quality : Excellent
Hi,

I need to destroy one variable in $_COOKIE (from a javascript appl.) and, because i don't use other $_COOKIE variables, I tried to do a brutal "unset($_COOKIE)"
however, when doing this before the 'session_start()' at the beginning of my script, the session is no more reachable (login lost, other session variable lost)

what the hell is the relation between Cookie and session in PHP ???
By: VGR Date: 31/12/2004 09:21:36 English  Type : Answer
The session ID is stored in a cookie on the users machine! By unsetting the cookie, you are destroying the reference to the session and so no session ID is given and the session is all lost.

and the server has also (usually) a "server cookie" on its own, containing all your session variables's values... and named after the sessionID :D

instead of unsetting all cookies, just delete the particular cookie you need. I don't think unset($_COOKIE) will actually destroy any cookies on the browser, it will just make them unreadable for the current PHP script. This is probably why session_start() isn't working.

To delete a cookie from the browser, you need to use setcookie() and pass an expiration time in the past, with an empty string as the value.

setcookie('deleteme', '', time() - 3600);
By: Bernard Date: 10/01/2005 09:25:20 French  Type : Comment
parfait, très clair, merci

Do register to be able to answer

EContact
browser fav
page generated in 954.443930 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page