LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Are PHP session variables held in memory when you leave a PHP site? (http://www.linuxquestions.org/questions/programming-9/are-php-session-variables-held-in-memory-when-you-leave-a-php-site-158051/)

Locura 03-15-2004 02:17 PM

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?

I am running PHP 4.2.3.

codedv 03-16-2004 05:16 AM

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

Locura 03-16-2004 08:07 PM

I finally got the session variable to be read by the return page, what I had to do was call the "session_start()" function on both pages. I didn't catch that from the online manual.

Tularis 03-17-2004 11:33 AM

Quote:

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 :)

kobs 03-17-2004 02:38 PM

sessions are destroyed when the user closes the browser.

Tularis 03-17-2004 03:09 PM

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)

ANSWER_THE_QUESTION 11-15-2008 04:15 PM

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.

jcookeman 11-15-2008 05:13 PM

A little reading would answer your plethora of questions. We're not here to hold your hand.

By the way, your piss take of a user name is not impressive or humorous in the slightest.

aarontwc 11-16-2008 10:18 AM

As far as my understanding of session holds, the session gets destroyed the moment you close the browser. What you are looking for is really cookies. $_COOKIE['whatever'] = "data" should be what you need. If you are worried about security issues, you can possibly encrypt the cookie information. Other than that, no real reasons why you can't use cookies over sessions.

aarontwc 11-16-2008 10:35 AM

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

Aaron
http://aarontwc.blogspot.com

graemef 11-16-2008 07:05 PM

Quote:

Originally Posted by ANSWER_THE_QUESTION (Post 3343125)
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.

sundialsvcs 11-16-2008 08:37 PM

Here's an accurate answer:
  1. 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.
  2. Each session is identified by a unique-and-arbitrary key value.
  3. 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."
  4. 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.)
  5. 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.


All times are GMT -5. The time now is 02:02 AM.