我的登录系统有这个问题。我在同一台计算机上有两个用户,userA 和 userB。用户 A 在一个浏览器中进入他的帐户;userB 可以在同一个浏览器中访问他的帐户。我的系统认为现在 userB 也是 userA 并且 userA 仍然连接到它自己的帐户,但他的名字显示为 userB。如果这两个用户可以访问不同的浏览器,则没有问题。
你知道我该如何解决这个问题吗?这是我的登录系统的代码:
<?php session_start();
$error = "";
$usuario1="";
$password="";
$form = $_POST['acceso_cuenta'];
if($_SERVER['REQUEST_METHOD']=='POST'){
$usuario1 = $_POST['login'];
$password1 = $_POST['pass'];
$strconn="dbname=postgres port=5432 host=127.0.0.1 user=xxx password=***";
$conn=pg_Connect($strconn);
if(!$conn){
// "Error connection!!!";
}else{
$query3 = "SELECT USUARIO FROM USERS WHERE USUARIO='$usuario1'
AND E_CONTRASENIA='$password' AND LEVEL='TAMER_LEVEL_3'";
$query2 = "SELECT USUARIO FROM USERS WHERE USUARIO='$usuario1'
AND E_CONTRASENIA='$password' AND LEVEL='TAMER_LEVEL_2'";
$result2=pg_query($conn,$query2);
$result3=pg_query($conn,$query3);
if(pg_num_rows($result3) != 0 ) { //success
if(isset($_SESSION['logged-in']) || isset($_SESSION['user'])){
session_unset();
session_destroy();
}
$_SESSION['logged-in'] = true;
$_SESSION['user']=$usuario1;
header('location: http://localhost/public_html/teacherLv3.php');
exit;
}else if(pg_num_rows($result2) != 0){
if(isset($_SESSION['logged-in']) || isset($_SESSION['user'])){
session_unset();
session_destroy();
}
$_SESSION['logged-in'] = true;
$_SESSION['user']=$usuario1;
header('location: http://localhost/public_html/teacherLv2.php');
exit;
}else {
$error = "WRONG DATA.";
}//
pg_close($conn);
} //else { $error = 'Don't leave blank spaces';}
}//end of if server
?>
这是teacherLv3页面的代码:
<?php
session_start();
// is the one accessing this page logged in or not?
if ( (!isset($_SESSION['logged-in']) && $_SESSION['logged-in'] !== true)) {
// not logged in, move to login page
session_destroy();
header('Location: login.php');
exit;
}
?>
<html>
<? echo "Welcome back Teacher_Level 3 MASTER {$_SESSION['user']} " ; ?>
</html>
这是teacherLv2页面的代码:
// is the one accessing this page logged in or not?
if ( (!isset($_SESSION['logged-in']) && $_SESSION['logged-in'] !== true)) {
// not logged in, move to login page
session_destroy();
header('Location: login.php');
exit;
}
?>
<html>
<? echo "Welcome back Teacher_Level 2 MASTER {$_SESSION['user']} " ; ?>
</html>