gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 06:48:34 25 4
gpt4 key购买 nike

我正在构建一个简单的网络应用程序。登录后,它应该将用户重定向到他们可以编辑的特定 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com