Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.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_Pdo - Fatal编程技术网

Php 第一次尝试登录被拒绝,但第二次尝试成功

Php 第一次尝试登录被拒绝,但第二次尝试成功,php,pdo,Php,Pdo,我目前在登录时遇到问题-第一次尝试登录总是被拒绝,但第二次尝试成功。你知道我该怎么解决这个问题吗 login.php pm/index.php ts/index.php 我认为在login.php中,您并没有启动会话,而是直接将值初始化为$\u session[$the\u name]。因此,在login.php文件的开头开始编写会话 首先,您在登录函数中设置了$_SESSION[$the_name],但似乎没有定义$the_name。这就是为什么我认为PHP通知应始终打开或未定义变量应大于通知

我目前在登录时遇到问题-第一次尝试登录总是被拒绝,但第二次尝试成功。你知道我该怎么解决这个问题吗

login.php

pm/index.php

ts/index.php


我认为在login.php中,您并没有启动会话,而是直接将值初始化为$\u session[$the\u name]。因此,在login.php文件的开头开始编写会话

首先,您在登录函数中设置了$_SESSION[$the_name],但似乎没有定义$the_name。这就是为什么我认为PHP通知应始终打开或未定义变量应大于通知的原因之一。您还设置了$\u SESSION['id']=$row['id'],并且未定义$row。@谢谢您的回复。我需要做哪些更改?
if(isset($_POST['pmsubmit']))
    {
    LoginSubmit('pm', 'pmname', 'pmpass');
    }

    if (isset($_POST['tssubmit'])) {
    LoginSubmit('ts', 'dept', 'tspass');
    }

function LoginSubmit($pm_or_ts, $the_name_input, $the_pass_input)
{
  global $pdo;
    $salt = "$2a$12ehTk6%^jswam)*usnyruhst";
  $posted_name = $_POST[$the_name_input];
    $posted_pass = crypt($_POST[$the_pass_input], $salt);   
  // check if password matches the one in the table
  $query = $pdo->prepare("SELECT * FROM db_pass WHERE pass = :pass");
  $query->execute(array(":pass" => $posted_pass));
  // if there is a match then we log in the user
  if ($query->rowCount() > 0)
  {
    // session stuff
    $_SESSION[$the_name] = $posted_name;
      $_SESSION['id'] = $row['id'];
    // refresh page
    header( 'Location: ' . $pm_or_ts . '/index.php' ) ;
    exit;
  } 
  // if there is no match then we present the user with an error
  else
  { 
    echo '
    <script>
    $(function() {
        $( "#dialog-message" ).dialog({
      modal: true,
      buttons: {
        Ok: function() {
          $( this ).dialog( "close" );
            }
        }
        });
    });
    </script>
        <div id="dialog-message" title="Incorrect password">
        The password you have provided is incorrect.<br>Please try again.
    </div>
    ';
  }
}
?>
<?php 
session_start();
setcookie("pmw", $_SESSION[$thename], time()+7200, '/');
require_once("../resources/php/connection.php");

if (empty($_SESSION[$thename]) || empty($_COOKIE['pmw']) ) {
    header("Location: ../login.php");
    exit;
}
?>
<?php 
session_start();
setcookie("ts", $_SESSION[$thename], time()+7200, '/');
require_once("../resources/php/connection.php");

if (empty($_SESSION[$thename]) || empty($_COOKIE['ts']) ) {
    header("Location: ../login.php");
    exit;
}
?>