我正在构建一个简单的web应用程序。登录后,它应该重定向用户到一个特定的地图页面,然后他们可以编辑。每个地图的地址与用户名和密码一起存储在一个简单的数据库中。
下面是我的代码登录(登录表单是在一个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");
------------------^
那个单引号?删除它。
on login failed:
header("Location: '..'..'..'?error=1");
------------------^
也删除单引号(谢谢@Petr R.),并使用绝对路径代替,可能路径是错误的。使用http://mysite.com/index.php?error=1
也更具体地与你的错误,我有问题与重定向的方式太笼统,它显示一个空白页吗?不加载?显示任何错误?
使用:
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$site
未被声明,这意味着它没有值。
所以给$site
一个值,它将工作