Forum Moderators: coopster

Message Too Old, No Replies

Sessions not carrying over!

         

Mendon

5:17 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



Hello, I've just started working on some scripts using sessions, but the session variables AREN'T carrying over, any suggestions?

First file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="hee.php">
<p>
<input name="textfield" type="text" id="textfield">
Test, wee<br>
<input name="textfield2" type="text" id="textfield2">
<br>
<input type="submit" name="Submit" value="Submit Test">
</p>
</form>
</body>
</html>


First PHP File:
<?PHP
session_start();
include 'includes/dbconnect.inc.php';
$name = $_POST['textfield'];
$pass = $_POST['textfield2'];
$query="SELECT * FROM Mendon WHERE owner='$name' and count_id='$pass'";
$result=mysql_query($query);
$num_rows = mysql_num_rows($result);
if ($num_rows!= 0) {
$_SESSION['name'] = $name;
$_SESSION['pass'] = $pass;
global $_SESSION;
echo "Session made!".$_SESSION['name']."<a href='gah2.php'>Click here to test!</a>";
} else {
echo "Wrong info!";
}
?>
The session was viewable in that last file, the final PHP file:
<?
session_start();
$name = $_SESSION['name'];
$pass = $_SESSION['pass'];
$name2 = "Ha!";
$nametest = $_SESSION['name'];
echo "Testing: ".$nametest." or ".$name2;
?>
The $name2 WON'T SHOW UP! So apparently the session isn't carrying over. >.< Any ideas?

HeadBut

5:58 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



Why use:
global $_SESSION;

?
What does this do?
I never have problems with Sessions and I've never used the "global $_SESSION;"
Are you sure the session is handled before the header is sent?(Your code should be at the top)

ergophobe

6:13 pm on Oct 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you have register_globals off (which you usually should and which is the default for PHP), you must use the superglobal $_SESSION.


If register_globals is disabled, only members of the global associative array $_SESSION can be registered as session variables. The restored session variables will only be available in the array $_SESSION.

See
[php.net...]
[php.net...]

Mendon

6:40 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



One of my various attempts at debugging, just a part I hadn't removed before pasting I guess. Anyways I just changed the tmp local path and POOF! It worked, so I have to speak to yahoo.