Hi, I encounter a problem during login.
My website flow looks like this:
home.php (session start, session assigns id, then user can login with email and password);
home.php call process.php to check for login.
process.php calls session->login(username, password) to validate parameter
session.php then calls database.php to run the actual query and execute.
result comes back to session.php
result comes back to process.php
result comes back to home.php
if verified, it will call header("Location: home.php");
my problem is at step 8 where when i calls home.php, it actually resets the session variables to Guest, or null.
Some sneak view of my code:
home.php
<?
include("include/session.php");
?>
....some html
<?
include("include/header.php");
include("include/loginbox.php");
include("include/category.php");
include("include/banner.php");
include("include/newproducts.php");
include("include/footer.php");
?>
</body>
</html>
process.php
....some other functions...
function procLogin(){
global $session, $form;
/ Login attempt /
$retval = $session->login($POST['user'], $POST['pass'], isset($POST['remember']), $POST['sid']);
/ Login successful /
if($retval){
header("Location: home.php");
}
/ Login failed /
else{
$SESSION['value_array'] = $POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: ".$session->referrer);
}
}
session.php
class Session
{
/ Class constructor /
function Session(){
$this->time = time();
$this->startSession();
}
function startSession(){
session_start(); //Tell PHP to start the session
/* Check if a session already exists */
if(!isset($_SESSION['userid']))
{
$this->userid = $_SESSION['userid'] = $this->generateRandID();
}
else
{
$this->userid = $_SESSION['userid'];
}
/* Determine if user is logged in */
$this->logged_in = $this->checkLogin();
.......some code below..
}
}
database.php
everything is correct here, the query returns true (found the user supplying username and password).
I think the problme might reside in the implementation of the referrer page.
If anyone can help me out this, it would be great. Thanks in advance.