By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Problem With Log in and Log Out using Session

P: 25
Hi , I am having problem with log in and log out . I have a main login page where one can login with the username and password stored in mysql database.
[PHP]

<?php
session_start();
//ob_start();
require_once 'functions.php';
$UserName = $_POST['UserName'];
$Password = $_POST['Password'];
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$adminAddress = getAbsolutePath().'adminlogin.php';
$userAddress = getAbsolutePath().'userlogin.php';
$samePage = getAbsolutePath().'login.php';
if ($_POST){
$error = login_check($_POST);
if (trim ($error)=="")
{
$accesslevel = accessLevel($UserName);
?>
<?php
if ($accesslevel == "admin"){
$_SESSION['level'] = "admin";
$_SESSION['username'] = $_POST['UserName'];
$_SESSION["userid"] = login($_POST);
include ('adminlogin.php');
//echo "<script language='javascript'> location.href='$adminAddress';
exit();
}
else if ($accesslevel == "user") {
$_SESSION['level'] = "user";
$_SESSION['username'] = $_POST['UserName'];
$_SESSION["userid"] = login($_POST);
include ('userlogin.php');
exit();
}
}
else {
//$_SESSION['loggedIn'] = false;
unset ($_SESSION['userid']);
unset ($_SESSION['username']);
unset ($_SESSION['level']);
echo "Error :$error";
}
}
//ob_end_flush();
?>
<BODY>
<FORM id=form1 name=loginform method=post>
[/PHP]

so after login user is directed to the corresponding page.

The problem is that when some user is logged in to the user page or admin page, at the same time if i want to login to the user page from other computers , it lets me login but after that whatever link i click in userlogin page, takes me back to login page. And i have to log in to userpage and click on log out and then it will work.
its quite strange and i dont know why it is acting like this.
Also in userlogin page i am have a link to other page which i am calling by
[PHP]

if ($_GET['mode'] == "basketball"){
include ('basket_closed.php');
}
and link is userlogin.php?mode=basketball

[/PHP]

My Log out script is
[PHP]

<?php
session_start();
//store to test if they were logged in
$old_user = $_SESSION['userid'];
//$_SESSION['loggedIn'] = false;
unset ($_SESSION['userid']);
unset ($_SESSION['username']);
unset ($_SESSION['level']);
session_destroy();
?>

[/PHP]

I need help on this...i couldn't came up with any clue, Any idea..
i really appreciate your help
Feb 19 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.