sessions

A

Anonymous

Guest
Please excuse the example below its an excersize I'm just learning. I'm having issues with the session variables. the below code runs ok however when I try and use the variable on another page it errors out with "Notice: Undefined variable: _SESSION in bla/bal/bla.php on line 31"

Code:
<?php
	session_start( );
while($row = mysql_fetch_array($result)){
	if ($_POST["passwordF"] == "$row[passfield]" && $_POST["usernameF"] == "$row[userfield]") {
	  $_SESSION['sessionuser'] = "$row[userfield]";
	  header("Location: bla/bal/granted.php");
	} else {
	  header("Location: bla/bal/denied.php");
	}
}
?>

below is what I'm using to recall the values from this session variable

Code:
<?php echo $_SESSION['sessionuser']; ?>
 
You need to use: session_start(); in the pages where you'll work with sessions.
That's what you need in the second file.
 
when you are using a header transfer...
Code:
<?php
header("Location: /yourpage.php?"+SID);
?>

it will ensure, that SESSION is migrated from the URL.
 
wow what a pain in the keister.. just spent 20 minutes trying different combinations to get this to work. I ended uo putting the session_start(); at the top of the header.php file which is included into the top of every page then, in the header the logger.php was included into that. perhaps a fix in 5.1 can make this easier :D

Also why can I not apply code with any length to it here on this forum? I get redirected to the following URL with no error message or anything..

http://www.php-forum.com/p/posting.php
 
There doesnt seem to be any problems with the session handlers in PHP. Therefore i do not believe that there will be any "fix" for anything ;)

What comes to postings: we seem to have a small bug there, however if you mark it as code: it should work fine. We didnt have so much time to look at this problem yet, but we will as soon as we get some spare time =)

Merry Christmas!
 
Back
Top