Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting session cookies??? 1

Status
Not open for further replies.

Apollo6

Technical User
Jan 27, 2000
418
US
Using Apache1.3.27/PHP4.3.1 on W2003Server

I have built a few scripts that pass session variables between pages to display data. I have also read on the session_destroy function and got it to work correctly, that is, it removes the cookie generated on, for example, Page1. However, I need the user to be able to go to Page2, which needs some of the session variables to display additional data.

If I use session_destroy() at the bottom on my script on Page1, and the user decides to go to Page2, my Page2 returns errors because no session variables got passed to it from Page1.

What I would like to be able to do is that when a user opens the app, a session is started, a cookie is written, and as long as they keep their browser up, the session cookie remains. If they close the browser, the session cookie is deleted from the server.

Am I correct in thinking I need to use the session_destroy() function?
 
You should only need to use session_destroy if your user is 'logging out' or you KNOW that the user is finished.
Sessions will time out on their own depending on the defaults on your system.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Hmmm... From your comments, I will not need to use session_destroy. What I am not sure of is the time out setting on the server. I do know that the cookies remain in the directory unless I manually go in and clean them out. Could I set a time limit on the session cookie and once the time is up, remove the cookie from the system?

Thanks for the feedback.
 
Sorry, according to this tutorial php freak session tutorial session cookies should just go away when the user closes the browser.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Apollo6:
faq434-4908 describes what happens when you invoke session_start() in your script, an how which php.ini settings modify the behavior of the PHP engine at that time.

As traingamer has said, by default, the cookies PHP's session-handling mechanism sets are held in the browser's memory and no longer exist when the browser is restarted.

If you want to remove a single session variable from a session store, I have good success with unset(). If I no longer need, for example, $_SESSION['foo'] in the user's current session, then:

unset ($_SESSION['foo']);

gets rid of that on value. If you want to keep the entire session going, but clear all values, I have found that:

$_SESSION = array();

works nicely.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Great information from both. Thanks for the feedback. It is working as I would expect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top