blackcell Posted February 15, 2008 Share Posted February 15, 2008 Can you pass a variable from page to page without passing it in the address bar? I think you can do this with globals but I don't understand "variable scopes" very well yet. Quote Link to comment Share on other sites More sharing options...
nogray Posted February 15, 2008 Share Posted February 15, 2008 http://us2.php.net/manual/en/ref.session.php First Page session_start(); $_SESSION['something'] = 'hello'; Second page session_start(); echo $_SESSION['something']; Quote Link to comment Share on other sites More sharing options...
blackcell Posted February 15, 2008 Author Share Posted February 15, 2008 Thanks Quote Link to comment Share on other sites More sharing options...
blackcell Posted February 18, 2008 Author Share Posted February 18, 2008 Now is data stored uniqe per session or do you need to make it unique by say...creating <?php $_SESSION['userIP']['something1']['something2'] ?> Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 it is unique per session, now two users will have the same sessid. Quote Link to comment Share on other sites More sharing options...
blackcell Posted February 18, 2008 Author Share Posted February 18, 2008 Ok. So if you start session() this creates the session. When is the session destroyed or released? When the user closes the browser or leaved the site? I have a feeling it works like htaccess but not for sure. Also, do you have to start session() on each page to recall the users session? Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 18, 2008 Share Posted February 18, 2008 like htaccess yes, all data is removed once the browser has been closed as the session id is lost. every page using session variables needs session_start() first, and each page after the START page needs a $_GET['PHPSESSID'] variable passed TO it. you would use the php CONSTANT: SID, to input the session id. ex. page1.php <?php session_start(); $_SESSION['Number'] = $_GET['Number']; echo("Page 1 Number Is: ".$_SESSION['Number']."<BR>". "<A href=\"page2.php?PHPSESSID=".SID."\">Next Page</a>" ); ?> page2.php <?php session_start(); $_SESSION['Number'] = $_GET['Number']; echo("Page 2 Number Is: ".$_SESSION['Number']."<BR>". "<A href=\"page3.php?PHPSESSID=".SID."\">Next Page</a>" ); ?> page3.php <?php session_start(); echo("Page 3 Number Is: ".$_SESSION['Number']."<BR>". "<A href=\"page4.php?PHPSESSID=".SID."\">Next Page</a>" ); ?> Quote Link to comment Share on other sites More sharing options...
blackcell Posted March 29, 2008 Author Share Posted March 29, 2008 If you pass and grab just the session ID will the entire $_SESSION array be available or do you have to pass all of them? I am trying to use this to store a user unique ID to an an array cell. After the login I will test at the beginning of each page for that array cell to have a value and if it doesn't they are redirected to the login page. Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 29, 2008 Share Posted March 29, 2008 Blackcell you can easily do this, $_SESSION variables are stored in an (encrypted?) file on the server. the SESSION 'ID' is maintained byt the name of the file on the server and a cookie/query_string on the client's browser. Every variable in the $_SESSION variable/array will be available as long as the clients browser can gived a valid Session ID, either by Cookie or URL Query. ---- Bear in mind Sessions do not last forever and not even dynamic lifetimes (cannot set them per user blah blah as far as i know of). To keep users logged in after a week or so you will need a cookie (there may be other ways like hardware identifiers with java etc but thats probably overkill), Don't use IP Addresses. Hope this helps, Quote Link to comment Share on other sites More sharing options...
blackcell Posted March 31, 2008 Author Share Posted March 31, 2008 Ok cool, now I am using this to store sessions variables now. I was using: <?php //Used to ensure uniqueness while moving through the site. $tier1 = 0; define("GSID",$tier1); define("USER",$tier1++); define("INFO1",$tier1++); define("INFO_SO_ON",$tier1++); //Then I the user will log on "code is not here" //session_start(); happens at the beginning of every page. //index.php $queriedUID = 1; //For example $_SESSION[GSID] = $queriedUID; //<----This DOES NOT work. $_SESSION['GSID'] = $queriedUID; //<----This WORKS //I am not passing any variables through the URL //main.php echo $_SESSION[GSID]; //<----This DOES NOT work. echo $_SESSION['GSID'];//<----This WORKS ?> Point being I am trying to define constants as number and increment those numbers. As I list it through the definition of the constant.This way I do not have to bother with organization but I know everything is unique, therefore I can call something in the $_SESSION array with something a little easier to remember in the Index. Some reason this isn't working but if I use just words in quotes the way it is done most of the time, it works. You might be saying why not just use the words? Well when I use defined constants it can be rolled into one file, and provide a reference point instead of digging through lines of code to see what I used for something. Quote Link to comment Share on other sites More sharing options...
uniflare Posted March 31, 2008 Share Posted March 31, 2008 I do not understand exactly why you do not want to use quotes? Can you explain the use of your constants a little more Quote Link to comment Share on other sites More sharing options...
blackcell Posted March 31, 2008 Author Share Posted March 31, 2008 It is fine to use quotes I just wanted to know what causes it not to work. I wanted to use constants so that there would be a standard index for every value. This will eventually be a more than one person project that deals heavily with loading a users values from a database into session variables. I wanted to make it so that everyone would know which values to use based on constants and they could reference a particular page to find that name. So its no biggy. I thought it looked cooler to (lame I know) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.