Howdy all,

I'm making an authentication script using sessions variables, but the varible seems to disappear when trying to access it from another page.

A simple form on the home page takes a user name and password, it then goes to an authentication page. The authenticate page is making a match and setting the session variables. I have tested this part and know that for sure. The authentication page then redirects in 2 seconds back to the originating page by a meta refresh. In this case, its the index page, but the index page does not recognize the session variable. Here is the code on the index page:

[B]if[/B] [B]($_SESSION[[/B]"authenticated"[B]]==[/B]"YES"[B])[/B]
[B]{[/B]
echo "Hi " [B].$_SESSION[[/B]"user_name"[B]];[/B]
[B]}[/B]
[B]else[/B]
[B]{[/B] 
?>
 
HTML form code here.
 
<?php
[B]}[/B] 
?>

It supposed to acknowledge the user, or put the log in form on the page, but it doesn't recognize the varible. Can anyone help? I've googled and looked at the code over and over, but can't see anything wrong.


Also, I'm using PHP 4.2.?, so I should not have to register the session variables as recommended for version 4.1 and above, correct?


Thanks,

Gil

Yes, I did have the

session_start();

and it does show the session variables on the authentication page when I echo the

$_SESSION["authenticated"]

variable. It returns 'YES', so I know its making the query on the mySQL database and matching with the submitted data.

When I redirect back to the index page, it will not echo the authenticated or user_name variable.

Thanks! That did it!

I'm more familiar with ASP session variables because that's what I use at work. This was the first time I have used a PHP session script, I though you only needed the session_start() once.

Much thanks, I have spent way too much time trying to figure out what was wrong!

This question has already been answered. Start a new discussion instead.