Page 1 of 1

[SOLVED] Session variables...

Posted: Fri Apr 01, 2005 8:05 am
by spacebiscuit
Hi I am having some trouble with session variables.

I have a form as follows:

Code: Select all

<form method="POST" action="../index.php">
 <tr><td>Account No.:</td><td><input type="text" size="15" name="username"></td></tr>
 <tr><td>Password:</td><td><input type="text" size="15" name="password"></td></tr>
<input class=button type="submit" value="Submit" name="submit">
</form>
I am then intialising session variables in the index.php script based on data passed with the above form:

Code: Select all

<?

session_start(); 
session_register ("username"); 
session_register ("password");

if(!$HTTP_SESSION_VARS["username"]){ 
	$HTTP_SESSION_VARS["username"]=$HTTP_POST_VARS['username'];
                                   }

if(!$HTTP_SESSION_VARS["password"]){ 
	$HTTP_SESSION_VARS["password"]=$HTTP_POST_VARS['password'];
                                   }

?>
Everything works great, I have tested this by echoing the session variables and they are outputting the correct data.

Now my index.php script calls an i-frame as follows:

Code: Select all

<iframe name=main src="main.php" width="581" height="354" scrolling=auto></iframe>


However if I now try to access the session variables in the i-frame script main.php as follows....

Code: Select all

echo $HTTP_SESSION_VARS["username"];
... they appear to be empty.

What am I doing wrong, are session variable not global in scope?

Thanks in advance.

Rob.

Posted: Fri Apr 01, 2005 8:13 am
by JayBird
have you got session_start(); in the main.php that is loaded into the iframe?

Posted: Fri Apr 01, 2005 8:21 am
by spacebiscuit
I hadn't no, that fixed the problem.

Many thanks!

Rob.