PHP Session Not Saving?
Posted: Sun Mar 01, 2009 1:20 pm
Here is my processLogin.php page which processes the login information:
Then, my simple test.php page to see if the Session is working:
Note: I also tried removing session_start() from the test.php page, but that didn't get the session variable to display correctly.
Nothing is getting displayed on the test page. I have used
on my processLogin.php page, and it displayed the information correctly. However, it seems as though the session variable is only being set for that one page view, as once I move away from the page it isn't being saved. I currently believe this is a web host problem, as I don't see anything wrong with my code. But, perhaps someone here can spot something?
Thanks!
Code: Select all
<?php
require_once("clsUser.php");
require_once("clsUserDB.php");
$strUsername = $_POST['txtUsername'];
$strPassword = $_POST['txtPassword'];
#creating the database object.
$objUserDB = new clsUserDB;
#creating a user object, and setting it equal to the object returned by the function GetUserData.
$objUser = $objUserDB->GetUserData($strUsername);
if ($objUser->getPassword() == md5($strPassword)) {
#starts a session for the user.
[b]session_start();[/b]
#sets a session variable called username equal to the username they used to login.
[b]$_SESSION['username'] = $objUser->getUsername();[/b]
#redirect the user to the index page.
header('Location: index.php');
exit;
}
?>Code: Select all
<?php
session_start();
echo $_SESSION['username'];
?>Nothing is getting displayed on the test page. I have used
Code: Select all
echo $_SESSION['username'];Thanks!