Forum Moderators: coopster

Message Too Old, No Replies

PHP Login Script

         

aanton05

10:21 pm on Nov 30, 2005 (gmt 0)

10+ Year Member



Hi. Thanks for all the help you guys. I have another problem that i can't figure out.

Below is a snippet of my "login.php" script. This script is called by an html form where users enter their username and password. If the login is successful the user is redirected to the "loggedin.php".

if($row['admin_access'] == 1){
$_SESSION['admin_access'] = true;
}

$login_time = mysql_query("UPDATE members
SET last_login=now()
WHERE id='{$row['id']}'");
}
header("Location: loggedin.php");

Below is a snippet of my "loggedin.php" script where i output: $_SESSION['first_name']

<p><font size="4" face="verdana, arial, helvetica">Welcome<?=$_SESSION['first_name'];?>!</font></p>
<p><font size="2" face="verdana, arial, helvetica">You have successfully logged in!</font></p>
<p><font size="2" face="verdana, arial, helvetica"><a href="logout.php">logout</font></p>

The problem is $_SESSION['first_name'] is not getting displayed in loggedin.php. However if i use
include 'loggedin.php'; instead of
header("Location: loggedin.php"); in my login.php file it works.

I hope this make sense. Thank you.

jatar_k

10:37 pm on Nov 30, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



have you started the session on the loggedin.php page?

session_start() needs to be at the top of all your pages/scripts that use sessions.

aanton05

10:43 pm on Nov 30, 2005 (gmt 0)

10+ Year Member



Thanks jatar_k. That fixed it. Have a nice day.