<tfoot id='yKLNV'></tfoot>
<i id='yKLNV'><tr id='yKLNV'><dt id='yKLNV'><q id='yKLNV'><span id='yKLNV'><b id='yKLNV'><form id='yKLNV'><ins id='yKLNV'></ins><ul id='yKLNV'></ul><sub id='yKLNV'></sub></form><legend id='yKLNV'></legend><bdo id='yKLNV'><pre id='yKLNV'><center id='yKLNV'></center></pre></bdo></b><th id='yKLNV'></th></span></q></dt></tr></i><div id='yKLNV'><tfoot id='yKLNV'></tfoot><dl id='yKLNV'><fieldset id='yKLNV'></fieldset></dl></div>

      <bdo id='yKLNV'></bdo><ul id='yKLNV'></ul>

  • <legend id='yKLNV'><style id='yKLNV'><dir id='yKLNV'><q id='yKLNV'></q></dir></style></legend>
      1. <small id='yKLNV'></small><noframes id='yKLNV'>

      2. 简单的登录会话 php

        时间:2023-10-11
        • <bdo id='hQCuZ'></bdo><ul id='hQCuZ'></ul>

          • <small id='hQCuZ'></small><noframes id='hQCuZ'>

            • <i id='hQCuZ'><tr id='hQCuZ'><dt id='hQCuZ'><q id='hQCuZ'><span id='hQCuZ'><b id='hQCuZ'><form id='hQCuZ'><ins id='hQCuZ'></ins><ul id='hQCuZ'></ul><sub id='hQCuZ'></sub></form><legend id='hQCuZ'></legend><bdo id='hQCuZ'><pre id='hQCuZ'><center id='hQCuZ'></center></pre></bdo></b><th id='hQCuZ'></th></span></q></dt></tr></i><div id='hQCuZ'><tfoot id='hQCuZ'></tfoot><dl id='hQCuZ'><fieldset id='hQCuZ'></fieldset></dl></div>

                <legend id='hQCuZ'><style id='hQCuZ'><dir id='hQCuZ'><q id='hQCuZ'></q></dir></style></legend>

                  <tfoot id='hQCuZ'></tfoot>
                    <tbody id='hQCuZ'></tbody>
                1. 本文介绍了简单的登录会话 php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  无法启动并运行我的会话.在过去的几个小时里,我一直在查看我的代码,但我看不出它有什么问题.我遇到的问题是,每次输入用户名和密码时,它只会将我重定向到登录页面,以便在应该显示securepage.php 时再次输入信息.

                  Having trouble getting my session up and running. I've been over looking my code for the past couple hours and I can't see to find what is wrong with it. The problem I am experiencing is that every time I type the username and password in, it just redirects me to the login page to type in the info again when it should be displaying the securedpage.php..

                  这是我的代码:

                  loginproc.php 页面 - 此页面逐步执行 if 语句并直接进入 else

                  loginproc.php page - This page steps through if statement and goes straight to the else

                  <?php
                  
                  // Inialize session
                  session_start();
                  
                  // Include database connection settings
                  include('../../model/database.php');
                  
                  // Retrieve username and password from database according to user's input
                  $login = mysql_query("SELECT * FROM user WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string($_POST['password']) . "')");
                  
                  // Check username and password match
                  if (mysql_num_rows($login) == 1) {
                  // Set username session variable
                  $_SESSION['username'] = $_POST['username'];
                  // Jump to secured page
                  header('Location: securedpage.php');
                  }
                  else {
                  // Jump to login page
                  header('Location: index.php');
                  }
                  
                  ?>
                  

                  securedpage.php 页面

                  <?php
                  
                  // Inialize session
                  session_start();
                  
                  // Check, if username session is NOT set then this page will jump to login page
                  if (!isset($_SESSION['username'])) {
                  header('Location: index.php');
                  }
                  
                  ?>
                  <html>
                  
                  <head>
                  <title>Secured Page</title>
                  </head>
                  
                  <body>
                  
                  <p>This is secured page with session: <b><?php echo $_SESSION['username']; ?></b>
                  <br>You can put your restricted information here.</p>
                  <p><a href="logout.php">Logout</a></p>
                  
                  </body>
                  
                  </html>
                  

                  database.php 页面

                  <?php
                  $dsn = 'mysql:host=localhost;dbname=sports_db';
                  $username = '';
                  $password = '';
                  $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
                  
                  try {
                      $db = new PDO($dsn, $username, $password, $options);
                  } catch (PDOException $e) {
                      $error_message = $e->getMessage();
                      include 'errors/db_error_connect.php';
                      exit;
                  }
                  
                  function display_db_error($error_message) {
                      global $app_path;
                      include 'errors/db_error.php';
                      exit;
                  }
                  ?>
                  

                  推荐答案

                  您不能混合使用 PDO 和 mysql .. 您正在 PDO 中创建查询并使用 mysql_*尝试将您的代码更改为

                  You cannot mix PDO and mysql .. You are creating query in PDO and using mysql_* Try changing your code to

                  <?php
                  
                  // Inialize session
                  session_start();
                  
                  // Include database connection settings
                  include('../../model/database.php');
                  
                  // Retrieve username and password from database according to user's input
                  $stmt = $db->prepare("SELECT * FROM user WHERE (`username` = :username) and (`password` = :password)");
                  
                  $result = $stmt->execute(array(':username'=>$_POST['username'],':password'=>$_POST['password']));
                  $num_rows = $stmt->rowCount();
                  // Check username and password match
                  if ( $num_rows > 0) {
                  // Set username session variable
                  $_SESSION['username'] = $_POST['username'];
                  // Jump to secured page
                  header('Location: securedpage.php');
                  }
                  else {
                  // Jump to login page
                  header('Location: index.php');
                  }
                  
                  ?>
                  

                  参考

                  这篇关于简单的登录会话 php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 XAMPP 中启用 XDebug 会减慢 phpmyadmin 下一篇:如何增加 phpmyadmin 的内存大小

                  相关文章

                  <legend id='XWxpX'><style id='XWxpX'><dir id='XWxpX'><q id='XWxpX'></q></dir></style></legend>
                2. <tfoot id='XWxpX'></tfoot>

                  1. <small id='XWxpX'></small><noframes id='XWxpX'>

                    <i id='XWxpX'><tr id='XWxpX'><dt id='XWxpX'><q id='XWxpX'><span id='XWxpX'><b id='XWxpX'><form id='XWxpX'><ins id='XWxpX'></ins><ul id='XWxpX'></ul><sub id='XWxpX'></sub></form><legend id='XWxpX'></legend><bdo id='XWxpX'><pre id='XWxpX'><center id='XWxpX'></center></pre></bdo></b><th id='XWxpX'></th></span></q></dt></tr></i><div id='XWxpX'><tfoot id='XWxpX'></tfoot><dl id='XWxpX'><fieldset id='XWxpX'></fieldset></dl></div>
                      <bdo id='XWxpX'></bdo><ul id='XWxpX'></ul>