<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

        simple login session php(简单的登录会话 php)
        • <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                      <legend id='XWxpX'><style id='XWxpX'><dir id='XWxpX'><q id='XWxpX'></q></dir></style></legend>
                      <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>
                              <tbody id='XWxpX'></tbody>