Click to See Complete Forum and Search --> : session variables
ubunreal69
Mar 14th, 2002, 05:31 PM
could someone please explain the concept and how to set them, get them, ect.... ? pls. i have a bit of trouble grasping the concept. :)
thanx for any help in advance
scoutt
Mar 14th, 2002, 06:04 PM
just like so
session_start();
$count = "yes";
session_register(count);
//so anywhere in the page all I have to do is
echo $count;
//or if they go to another page it is the same thing.
// whenever you register a session the variable is easy access.
// it is there anytime you want it. as long as you don't end the session.
ubunreal69
Mar 15th, 2002, 05:10 AM
session_start();
$count = "yes";
session_register(count);so "session_start();" basically registers thee session ??? and "session_register(count);" registers the "$count" variable in the session. i think thats correct isnt it ?
scoutt
Mar 15th, 2002, 07:39 AM
kind of. session_start(); tells the parser to start the session and find the directory to save the session and then you are correct on the last one. session_register(); registers the variable in the session file.
ubunreal69
Mar 16th, 2002, 06:53 AM
thanx a lot scoutt, i think session variables are going to replace cookies on my page now, since i dont use cookies for longer than a session anyway. (with the exception of the "Poll") :)
thanx again
I Robert I
Mar 16th, 2002, 09:18 AM
Hey there just joined up today when I saw this topic.
If it's ok with you ubunreal69 I'll post a followup question.
Is there some way of controlling how long the session cookie will be stored on the clients computer without editing the config file? As it is now the session is destroyed when the user closes the browser window. I'd like it to save the cookie for, say 1 week. Possible?
The reason I'm asking is because one of the free hosts I'm using doesn't, obviously, allow the users to edit the config file.
ubunreal69
Mar 16th, 2002, 10:15 AM
In reply to roberts question.
session variables are only available for the session and so are cookies when you dont specify a period for them to stay active.
cookies stay on the users machine for as long as you specify, but as i said, if you dont specify a time period then they are session only.
hope this helped :)
scoutt
Mar 16th, 2002, 10:42 AM
now to capitalise on this question.
Sessions don't stay on the clients computer. they live on the server and stay there how ever long the server is setup to let them live, generally an hour. that setting is in the php.ini I think.
if you want it to stay on the clients computer, then use regular cookies.
I Robert I
Mar 16th, 2002, 10:57 AM
Mm yeah, I just thought that sessions "allways" was a combination of session information located on the server and a cookie on the client machine that "revives" the session when the user comes back. I changed the setting for this on my own machine in the php.ini file like so:
[Session]
; Handler used to store/retrieve data.
session.save_handler = files
; Argument passed to save_handler. In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this
; variable in order to use PHP's session functions.
session.save_path = some path
; Whether to use cookies.
session.use_cookies = 1
; Name of the session (used as cookie name).
session.name = blaaaaa
; Initialize session on request startup.
session.auto_start = 0
; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 604800
What I'd like to know is if you could override this setting in the sourcecode of your pages?
I don't know maybe I'm just talking out of my ass :p I've only been reading PHP for 4 weeks so...
The project I'm working on is this btw: http://bender.homeftp.net:4224/ (if it's down, I'm probably asleep)
scoutt
Mar 16th, 2002, 11:02 AM
no you can't as far as I know change the session.cookie_lifetime on the server. you can change a few other stuff like colors it uses but not stuff like that. the way around it is to store the session in a database. that is what this site does. they also use a cookie in conjuction with the session. but the cookie is for mostly in for remembering your password and login.
I Robert I
Mar 16th, 2002, 11:15 AM
Ok, to bad :|
I used cookies to handle login before but changed it to sessions cause I thought it was a bit neater. Would hate to have to recode all the login stuff to incorporate normal cookies again...
Nah my users just have to log in everytime for now. Thanks for the help guys!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.