Are PHP session variables held in memory when you leave a PHP site?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Are PHP session variables held in memory when you leave a PHP site?
I want to store some info in a PHP session variable, and have it be remembered as long as the session remains active, regardless of whether or not a user leaves my site for another site. Does leaving the domain cancel the session, or is this possible?
Session variables are stroed on the clients computer in the form of cookies or can be transported via the URL. You can set these variables in your PHP script and restore them the next time the user requests your page. Here's the documentation on session function in PHP: http://www.php.net/manual/en/ref.session.php
Originally posted by codedv Session variables are stroed on the clients computer in the form of cookies or can be transported via the URL. You can set these variables in your PHP script and restore them the next time the user requests your page. Here's the documentation on session function in PHP: http://www.php.net/manual/en/ref.session.php
actually, you're wrong at that... Session variables themselves are stored on the *server*. Your session is the appointed a unique session id, which is saved as a cookie. When you go to the page, the id is sent, and php automatically retrieves the session variables from the server
take it from me... I know... sessions are destroyed when they haven't been linked to for a certain amount of time. When the browser closes, the session-id cookie is destroyed, in turn this means the session that it links to has no more links. The gc (garbage collector), which is randomly initiated at certain intervals, then disposes of sessions that haven't been linked to in a set amount of time. It's all explained in the php manual (http://nl.php.net/manual/en/ref.session.php)
Okay, I didn't really read your second post. Now in response to your other post.
The first time you call session_start(), PHP basically generates a new session ID and creates an empty file to store session variables (therefore, the answer is, its in disk on server). PHP also sends a cookie back to the client that contains the session ID.
But since the cookie is send in part of the HTTP headers in response to the broswer, you have to call the session_start function on the end of the server before you can access these session information using $_SESSION['whatever'].
If you don't access session variables for a while, these information would be destroyed by PHP garbage collector.
i dont know what you are trying to do here. But if you are trying to manipulate session so that you can prolong it and so that it does not destroy itself after you close the browser, you need to use session + cookies explicitly. That way, the cookies can store the session_id of the server on the client end. Making it possible for you to manipulate session stuffs. Other than that, i highly doubt that you can actually manipute the PHP stuffs on the server end unless you create an application on top of it [php].
Yeah. Great. It's on the server side. The session is on the server side.
But is is in memory? or is it on disk?
Is it inside a huge file with other things? or it's own file?
Where is it?
How can I "see" it and know it's there?
Do I have to call functions to see it? Is that the only way?
If it's on disk, I can find it and look at it. Delete it, et c. It's *similiar* to a client-side cookie.
If it's in memory, then i need to run a function to return a value. I need to run a function to destroy it.
If it's in memory does it die on it's own? how? when? what are the conditions?
Do you see what I'm asking.
I need to know that it is tangible so I can effectively manipulate it. How do I grab it and look at it?
Don't point at manuals. I've already looked there, and it didn't help.
What do YOU do?
Or do you not even try to do these things. If you don't know, then just say "I don't know." or remain silent.
If you do know. Then explain, please.
It all depends on how php has been set up. Typically it is stored on a file in the /tmp directory. Despite your comment the manual does explain it, check out the chapter on Session handling functions. The function session_save_path() will help.
Session information is stored exclusively "on the server." PHP provides several built-in mechanisms to choose from to determine how-and-where you accomplish this feat on the server.
Each session is identified by a unique-and-arbitrary key value.
The server must be able to determine, from the incoming HTML data-stream from the user's browser, what session-key is associated with it. Usually, this is done by storing the session-key in a "cookie."
Session-information is not retained forever. Instead, periodic garbage collection is done to purge information that may be associated with keys that haven't been used for a while. (PHP once again provides several strategies to choose from.)
On the client-side, cookies are usually persistent for some time ... and you can usually suggest how long they should be kept. But the user is free to delete cookies at any time, and to selectively refuse to store or to modify any of them. (In fact, my browser purges all cookies whenever I close the browser.)
If you want to provide long-term storage, i.e. over several days or months, just think about how this site stores, say, "private messages." You log-in, and (in the current session-information) the site remembers that you've done so and who you are. Knowing "who you are," and that you are in fact who you say you are, the site can retrieve from long-term storage (by some appropriate means...) your private messages and show them to you.
Last edited by sundialsvcs; 11-16-2008 at 09:38 PM.