PHP - 用户登录后,重定向到存储在数据库中的地址

标签 php mysql redirect authentication

我正在构建一个简单的网络应用程序。登录后,它应该将用户重定向到他们可以编辑的特定 map 页面。每个 map 的地址与用户名和密码一起存储在一个简单的数据库中。

下面是我的登录代码(登录表单在 index.php 页面上)

我无法使重定向正常工作,因为“站点”是存储地址的行名称。

include 'db_connect.php';
    include 'functions.php';
    sec_session_start(); // Our custom secure way of starting a php session. 

    if(isset($_POST['email'], $_POST['p'])) { 
       $email = $_POST['email'];
       $password = $_POST['p']; // The hashed password.
       if(login($email, $password, $mysqli) == true) {
          // Login success and shoud redirect to 'site'
        header("Location: '$site");
        } else {
      // Login failed
     header("Location: '..\..\..\?error=1");

   }
} else { 
   // The correct POST variables were not sent to this page.
   echo 'Invalid Request';
}

最佳答案

登录成功时:

header("Location: '$site");
------------------^

那个单引号?删除它。

登录失败:

 header("Location: '..\..\..\?error=1");
 ------------------^

也删除那个单引号(Thx @Petr R.)并改用绝对路径,也许路径是错误的。使用像 http://mysite.com/index.php?error=1

这样的东西

还要更具体地说明您的错误,我遇到的问题是重定向过于笼统,是否显示空白页?不加载?显示任何错误?

使用:

error_reporting(E_ALL);
ini_set('display_errors', 'On');

如果您在生产环境中,则显示您的错误。

关于PHP - 用户登录后,重定向到存储在数据库中的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17088902/

相关文章:

php - 使用 mySQL 在 PHP 中 SQL 不返回结果

PHP 正则表达式验证

java - lighttpd : redirecting to another page causes duplicated hostname in path

javascript - 如何在视频播放完毕后重定向到不同的 URL

linux - 每次返回新输出时将应用程序输出的最后一行重定向到文件

java - Spring mvc 应用程序与 php 论坛和 wiki 集成

php - 如何将 4 个单选按钮(每种颜色 4 种)存储到我的数据库中?

php - 如何在 PHP 中自动检测夏令时?

php - 在一行中显示两行或多行

MySql 拒绝使用索引