View Full Version : PHP equivalent of ASP session variables
abzoid
November 26th, 2003, 12:20 AM
OK, the PHP education continues. I need to set a variable on page X then later on Page Y use that variable. In ASP I'd assign the value to a Session variable, but I cannot find an equivalent PHP contruct in my PHP books or in my search of this site. There has to be something similar and I'm just not calling it by the right name in order to find it.
H E L P, please?
λ
November 26th, 2003, 02:47 AM
I've never used sessions, and for some reason they're not working on my server at the moment, but this is what you need to use(I believe)...
First you call session_start()
session_start();
$_SESSION['sessionVar'] = "sessionvalue";
//then, when the user clicks on a hyperlink,
//the variable is still there, and you can access is from $_SESSION['sessionVar']
there is more info in the PHP manual section on sessions... I found a session tute on devshed, but it looked out of date slightly.
abzoid
November 26th, 2003, 09:30 AM
OK, that's not much different than ASP, other than having to start the session yourself. Thanks.
hamza84
November 26th, 2003, 11:56 PM
You should also keep in mind that whnever you want to access a session variable, you have to use session_start in that script and should do so in the beginning, b4 passing any headers. I suppose you already knew this, but still went ahead in case you didn't ;)
Jubba
November 27th, 2003, 12:15 AM
You can read thru this for more on sessions. It might be a little overbearing at first, but you have a lot of experience with SS-scripting, so you should be able to weed out the bad info from the good stuff. :) If you need anything else just let me know:
http://us4.php.net/manual/en/ref.session.php
session in PHP are cake once you get used to them. :thumb:
abzoid
November 27th, 2003, 09:21 AM
I've just read through it quickly and most of it made sense. I'll hit it again in more detail when I have more time to digest it and try a few things.
Thanks
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.