Hello
Having trouble retrieving the session variables.
I am using the $_SESSION variable to store the sessions and the values are set. However on the next page load, the values are lost and the user is not logged in.
I am just trying to do a simple authentication...
here is my code:
<index.php>
<?
include "sessions-lib.php";
include "auth-lib.php";
authenticate_user();
echo "i am logged in";
?>
<sessions-lib.php>
<?
session_name('restricted_a
rea');
session_start();
?>
<auth-lib.php>
function authenticate_user() {
global $reseller_id,$password,$at
tempt_logi
n;
if (isset($reseller_id) && isset($password) && isset($attempt_login) ) {
attempted_login($reseller_
id,$passwo
rd);
}
elseif( isset($_SESSION["reseller_
id"]) && isset($_SESSION["is_author
ised"]) ) { #check for existing session
return 1;
}
else {
display_login_form();
exit;
}
# else continue ...
}
function attempted_login($reseller_
id,$passwo
rd) {
# authenticate user if details are correct
$reseller_id = ereg_replace(" ","",$reseller_id);
$password = ereg_replace(" ","",$password);
if(!authenticate_user($res
eller_id,$
password))
display_login_form('Unable
to authorise. Supplied details are incorrect.');
exit;
}
$_SESSION["reseller_id"] = $reseller_id;
$_SESSION["is_authorised"]
= 1;
return true;
}
?>
so the index page includes the sessions-lib which should load the available sessions in and initialise $_SESSION ?
then when authenticate_user() is called, it should be able to see the session variables.
all it does is
1. display_login_form()
so u enter your details
2. shows index page "i am logged in"
3. reload page and u will be prompted with the display_login_form() .
any ideas? do i have to anything further to set the session variables?
have been to php.net and looked through there for an hour or so but i must be missing somthing.
thanks heaps for your help :)
Cheers
Steve
Start Free Trial