Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 防止会话存储中的重复输入_Php_Session - Fatal编程技术网

Php 防止会话存储中的重复输入

Php 防止会话存储中的重复输入,php,session,Php,Session,我正在尝试使用数组中的登录详细信息登录,所有这些都存储在这个脚本中 我添加了会话欠费,其中每个登录名都将存储在session.txt中,我希望在session.txt中不会有重复的登录名,以防止重复登录,如果您已经登录,则无法再次登录 此脚本中的第一个用户名被禁止登录两次,同时其他人也可以登录,我要做的是避免在我的session.txt中重复输入 这是我的密码: <?php session_start(); /* Starts the session */ /* Check Lo

我正在尝试使用数组中的登录详细信息登录,所有这些都存储在这个脚本中

我添加了会话欠费,其中每个登录名都将存储在session.txt中,我希望在session.txt中不会有重复的登录名,以防止重复登录,如果您已经登录,则无法再次登录

此脚本中的第一个用户名被禁止登录两次,同时其他人也可以登录,我要做的是避免在我的session.txt中重复输入

这是我的密码:

<?php session_start(); /* Starts the session */

    /* Check Login form submitted */    
    if(isset($_POST['Submit'])){
        /* Define username and associated password array */
        $logins = array('Emmanuel' => '1234','John' => 'Faith123','Favour' => '12345','Abbey' => 'Godisgood');

        /* Check and assign submitted Username and Password to new variable */
        $Username = isset($_POST['Username']) ? $_POST['Username'] : '';
        $Password = isset($_POST['Password']) ? $_POST['Password'] : '';

        /* Check Username and Password existence in defined array */        
        if (isset($logins[$Username]) && $logins[$Username] == $Password){
      $handle = "sessions.txt";
      $data = file_get_contents($handle);
$line = explode("\n", $data);
foreach ($line as $user) 
{
if($Username==$user)
{
  echo"You can not vote twice";
}
else
{
            /* Success: Set session variables and redirect to Protected page  */
            $_SESSION['UserData']['Username']=$logins[$Username];
      $string = $Username . "\r\n";
      $handle = fopen("sessions.txt", 'a');
      fwrite($handle, $string);
      fclose($handle);
            header("location:../president");
            exit;
        } }else {
            /*Unsuccessful attempt: Set error message */
            $msg="<span style='color:red'>Invalid Login Details</span>";
        }
    }
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>LOGIN</title>
<link href="./css/style.css" rel="stylesheet">
</head>
<body>
<div id="Frame0">
  <h1>LOGIN</h1>
</div>
<br>
<form action="" method="post" name="Login_Form">
  <table width="400" border="0" align="center" cellpadding="5" cellspacing="1" class="Table">
    <?php if(isset($msg)){?>
    <tr>
      <td colspan="2" align="center" valign="top"><?php echo $msg;?></td>
    </tr>
    <?php } ?>
    <tr>
      <td colspan="2" align="left" valign="top"><h3>Login</h3></td>
    </tr>
    <tr>
      <td align="right" valign="top">Username</td>
      <td><input name="Username" type="text" class="Input"></td>
    </tr>
    <tr>
      <td align="right">Password</td>
      <td><input name="Password" type="password" class="Input"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input name="Submit" type="submit" value="Login" class="Button3"></td>
    </tr>
  </table>
</form>
</body>
</html>