LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-15-2004, 03:17 PM   #1
Locura
Member
 
Registered: May 2003
Distribution: Ubuntu 6.10 SE, Mac OS 10.4.8
Posts: 370

Rep: Reputation: 30
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.
 
Old 03-16-2004, 06:16 AM   #2
codedv
Member
 
Registered: Nov 2003
Location: Slough, UK
Distribution: Debian
Posts: 146

Rep: Reputation: 15
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
 
Old 03-16-2004, 09:07 PM   #3
Locura
Member
 
Registered: May 2003
Distribution: Ubuntu 6.10 SE, Mac OS 10.4.8
Posts: 370

Original Poster
Rep: Reputation: 30
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.
 
Old 03-17-2004, 12:33 PM   #4
Tularis
LQ Newbie
 
Registered: Mar 2004
Posts: 5

Rep: Reputation: 0
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
 
Old 03-17-2004, 03:38 PM   #5
kobs
Member
 
Registered: Mar 2004
Location: 127.0.0.1
Distribution: FreeBSD 5.3-STABLE, Slackware 10-CURRENT, Debian Sarge
Posts: 51

Rep: Reputation: 15
sessions are destroyed when the user closes the browser.
 
Old 03-17-2004, 04:09 PM   #6
Tularis
LQ Newbie
 
Registered: Mar 2004
Posts: 5

Rep: Reputation: 0
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)
 
Old 11-15-2008, 05:15 PM   #7
ANSWER_THE_QUESTION
LQ Newbie
 
Registered: Nov 2008
Posts: 1

Rep: Reputation: 0
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.
 
Old 11-15-2008, 06:13 PM   #8
jcookeman
Member
 
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
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.
 
Old 11-16-2008, 11:18 AM   #9
aarontwc
Member
 
Registered: Oct 2008
Posts: 66

Rep: Reputation: 15
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.
 
Old 11-16-2008, 11:35 AM   #10
aarontwc
Member
 
Registered: Oct 2008
Posts: 66

Rep: Reputation: 15
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
 
Old 11-16-2008, 08:05 PM   #11
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by ANSWER_THE_QUESTION View Post
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.

Last edited by graemef; 11-16-2008 at 08:09 PM.
 
Old 11-16-2008, 09:37 PM   #12
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,455

Rep: Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172
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.

Last edited by sundialsvcs; 11-16-2008 at 09:38 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
php: session variables lost while redirecting appas Programming 2 10-13-2004 10:18 AM
PHP session variables in a database rmanocha Programming 0 07-16-2004 05:18 AM
PHP if statements and variables antken Programming 4 09-24-2003 01:45 PM
Question about php variables lostboy Programming 5 08-07-2003 08:38 PM
php variables not being passed on tpat Linux - Software 1 01-11-2003 04:11 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration