这是PHP会话的问题..其中用户可以与相同/不同的凭据同一个浏览器多次登录..如何防止在同一个浏览器多次登录使用PHP
1)用户1登录..
2)用户1尝试在新标签页中打开LoginIndex.php ..
3)它显示LoginIndex.php页,而不是以前在登录页面(用户1登录)...
4)接受用户1再次登录相同/不同凭据..在同一个br owser
我不知道为什么它再次服用登录值..
这里是LoginViewController.php
<?php
if (!isset($_POST['submit']))
{
?>
<html>
<table align="center">
<tr>
<td>
<input class="input" type="text" name="uname" id="uid" placeholder="Username" >
</td>
</tr>
<tr>
<td>
<input class="input" type="password" name="pwd" id="pid" placeholder="Password" >
</td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="" > </td>
</tr>
</table>
<?PHP
}
else
{
//If you are submitting the form insert the details into database
$Username = $_POST['uname'];
$Password = $_POST['pwd'];
session_start();
If (!(empty($Username) && empty($Password)))
{
$model = new UsersModel();
$rowsCount = $model->checkUser($Username,$Password,$User_Type);
if ($rowsCount!=0)
{
$_SESSION['user'] = $Username;
header("location:loggedin.php");
} else
{
echo '<script type="text/javascript">alert("Enter username and password correctly");
window.location.href="LoginViewController.php";</script>';
}
}
}
?>
下面的代码段已登录in.php代码是什么我的工作吧...
<?php
header("Cache-Control: private, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: Fri, 4 Jun 2010 12:00:00 GMT");
include('GenericClasses/GenericCollectionClass.php');
include('Models/UsersModel.php');
include('DataObjects/Users.php');
include('DatabaseAccess/DBHandler.php');
session_start();
if(!isset($_SESSION['user']))
{
header('Location: LoginViewController.php');
exit();
}
echo '"<div style="background:white; text-align:right"> Login as:'.$_SESSION['user'].'
<a href="LogoutViewController.php" style="text-align:right">Logout</a></div>"';
?>
任何建议是可以接受的...
我试过答案..但我无法获得重定向...为什么它不重定向...它只是显示一个空白的页面.. –
问题可能是你在标题功能之前回应一些东西。你也可以使用meta-http重定向...确保你在使用头文件之前不要回显任何东西。这只是提示可以做什么...如果你使用codeigniter,那么它们有一个叫做重定向(参数)..您也可以使用该功能 – dhaval
我删除了回声声明...之后,它也没有重定向..在这里,我遵循我的教练给出的一些mvc架构,我是新来的..如果你有任何经验帮助我解决这个问题 –