blackcell Posted March 29, 2008 Share Posted March 29, 2008 Hello, I have been reading for the past day on sessions and I can't figure out what I am doing wrong. From my reading I understand that in order to make session variables available from one page to the next is: <?php //index.php session_start(); $_SESSION[0] = "something123"; //seperate.php session_start(); echo $_SESSION[0]; //Should print "something123" ?> I am not getting the desired outcome. I am including a bit of my code. Basically I have something called engine.core.php and that will have everything that needs to be loaded on every page like session_start() and including files that need to be and such. <?php //engine.core.php snippet session_start(); //constants.php snippet $tier1 = -1; $tier2 = -1; define("SID",$tier1++); define("SYS",$tier1++); define("SYS_VER",$tier2++); define("SYS_ROOT",$tier2++); define("SYS_PAGE",$tier2++); define("SYS_COMMAND",$tier2++); define("USER",$tier1++); define("USER_ID",$tier2++); //validate.inc.php snippet //This is included if the person is not on the login, or register page (attempting to go past the login via link) if($_SESSION[sYSID] == ""){ die("Dead [LINK TO REDIRECT EVENTUALLY]"); } //login.php snippet require("engine.core.php")//session_start() // . // . // . // . User logs in, password is checked, and user unique id is retrieved from database to use a a key for all other info // . The queried number is saved as $queryID. I have tested this and for sure retrieving a number so the mistake is not on my query. $_SESSION[sID] = $queryID; ?> I get through the login process and go to my next screen where validate.php will be included and it kills me. I echo the <?php $_SESSION[sID] ?> and it is empty? Can anybody offer any advice or suggestions on what is happening and how I need to pass Session vars? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2008 Share Posted March 29, 2008 Put the following two lines after your first opening <?php tag on each page - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
blackcell Posted March 29, 2008 Author Share Posted March 29, 2008 Wow, never knew I was doing so many things wrong. What is this though? Notice: Unknown: Skipping numeric key 1. in Unknown on line 0 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2008 Share Posted March 29, 2008 SID is a predefined php constant, you should use something else in your code. Quote Link to comment Share on other sites More sharing options...
blackcell Posted March 29, 2008 Author Share Posted March 29, 2008 Ok now i am using a defined constant GSID Quote Link to comment Share on other sites More sharing options...
blackcell Posted March 29, 2008 Author Share Posted March 29, 2008 Now I got it to recognize something but it is returning Array. I check the $_SESSION[GSID] and echo it before I leave the login page and I get the correct integer. As I go to the validate code segement it returns Array. What gives? Quote Link to comment Share on other sites More sharing options...
blackcell Posted March 29, 2008 Author Share Posted March 29, 2008 Found it i think. I guess you can't use defined constants for the $_SESSION array index. Instead of $_SESSION[GSID] I used $_SESSION['GSID'] and it worked fine. 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.