bobbyM Posted September 17, 2007 Share Posted September 17, 2007 Hi, I am using the following: Apache version 1.3.37 (Unix) PHP version 4.4.4 MySQL version 4.1.22-standard I have a page which sets a few $_SESSION variables as such: $_SESSION['username'] = Bobby; $_SESSION['authentic'] = 1; I didn't use session_start(); at the beginning of this page because from what I read elsewhere there is no need to when using $_SESSION[](only when using session_register()). Now, when I click a link and go to a new page (same domain and same window) none of the $_SESSION variables are read. I just get empty when I echo $_SESSION['username']. Anybody have any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/69678-solved-_session-not-sent-across-multiple-pages/ Share on other sites More sharing options...
GingerRobot Posted September 17, 2007 Share Posted September 17, 2007 Well, you read wrong You MUST call session_start(); before any use of the $_SESSION superglobal. And it MUST be called before any output to the browser. Otherwise, you'll get an error (or a blank page as seems to be the case - im getting display_errors is turned off in your php setup). Link to comment https://forums.phpfreaks.com/topic/69678-solved-_session-not-sent-across-multiple-pages/#findComment-350105 Share on other sites More sharing options...
bobbyM Posted September 17, 2007 Author Share Posted September 17, 2007 Hrm, i added it to the top of my index.php page and I get the same result. I'll try showing you what I have done. Index.php <?php session_start(); include('../constant.php'); include('../incl.php'); ?> <html><head></head> <?php $password = $_POST['password']; $username = $_POST['username']; $enc_password = md5(sha1($password)); $query = "SELECT users_id, username, admin FROM users WHERE username = '". $username ."' AND password = '". $enc_password ."'"; $result = mysql_query($query); $row = mysql_num_rows($result) or die(mysql_error()); if($row) { while($rows = mysql_fetch_row($result)) { $_SESSION['id'] = $rows[0]; $_SESSION['username'] = $rows[1]; $_SESSION['authentic'] = 1; $_SESSION['admin'] = $rows[2]; } } include(menu.php); //bad formto include like this? No clue..... menu.php simplified <html><head></head> <body> <?php echo '<a href="cart.php">Cart</a>'; ?> </body></html> finally, cart.php where the $_SESSION variables aren't showing <html> <head> <body> <?php echo "hi"; echo $_SESSION['admin'].'is admin'; echo $_SESSION['username'].'is user'; ?> </body></head></html> Link to comment https://forums.phpfreaks.com/topic/69678-solved-_session-not-sent-across-multiple-pages/#findComment-350122 Share on other sites More sharing options...
bobbyM Posted September 17, 2007 Author Share Posted September 17, 2007 G'ah, i forgot to add session_start(); to the second page. I assumed once it is opened it stays opened for all pages in that browser window. You were right, it works now that I added it Thanks soooo much Ginger! Link to comment https://forums.phpfreaks.com/topic/69678-solved-_session-not-sent-across-multiple-pages/#findComment-350148 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.