Hey all.
Trying to get sessions to work on my app. The issue is this. When the
main page loads I check for a session variable uname to see if the
user is logged in and display a "hello, username" message, or
otherwise use "guest." Pretty straightforward. Then I have a login
form that uses AJAX calls to log the user in. If the login info is
correct, I set $_SESSION['uname'] to the username. However, if I then
refresh the main page, the session info is gone. Here's a glimpse at
what's going down....
From index.php:
<?php
session_start();
?>
....
<span>Hello, <?php if(isset($_SESSION['uname'])){
echo $_SESSION['uname'];
}
else {
echo 'Guest';
}?></span>
From login.php:
<?php
$dbh=mysql_connect ...
...
//do this on login SUCCESS:
echo 'Login Successful';
$_SESSION['uname'] = $_POST['un'];
};
?>
I can't use session_start() in login.php; it gives me an error saying
http headers have already been sent.
Any suggestions?