[SOLVED] Session variables...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

[SOLVED] Session variables...

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

have you got session_start(); in the main.php that is loaded into the iframe?
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post by spacebiscuit »

I hadn't no, that fixed the problem.

Many thanks!

Rob.
Post Reply