我对 PHP 有点陌生,我正在尝试在登录表单中执行以下操作: - index.php:登录(链接到 reglogin.php) - reglogin.php:注册或登录。登录时:检查电子邮件是否在数据库中。如果是这样-> 登录并转到成功页面。重定向到成功页面不起作用。
索引.php
<?php session_start(); $page=(isset($_GET['page']))?$_GET['page']:"index"; ?>
<!DOCTYPE html>
....
<body>
<?php include 'includes/header.php'; ?>
<div class="content">
<?php
$frontpage="page/home.php";
$page404="page/404.php";
$folder="page/";
if ($page=="index") {
include_once($frontpage);
}
else {
include_once((file_exists($folder.$page.".php"))?$folder.$page.".php":$page404);
}
</div>
</body>
包括/header.php
<div class="header">
<?php
if (isset($_SESSION['email'])) {
?>
<ul><li><a href="index.php?page=logout">Log out</a></li></ul>
<?php
}
else { ?>
<ul><li><a href="index.php?page=reglogin">Log in</a></li></ul>
<?php }
?>
</div>
重新登录.php
<?php if (!isset($_SESSION['email'])) { ?>
<form method="post" action="index.php?page=logincheck" class="loginform">
<fieldset>
<input type="text" name="login_email" />
<input type="text" name="login_password" />
<input type="submit" name="login_submit" />
</fieldset>
</form>
<?php } else { echo "U are already logged in"; } ?>
登录检查.php
<?php
session_start();
include 'includes/config.php';
// if session['email'] doesn't exit
if (!isset($_SESSION['email'])) {
if (isset($_POST['login_email']) && isset($_POST['login_password'])) {
$login_email = $_POST['login_email'];
$login_password= $_POST['login_password'];
if (!empty($login_email) && !empty($login_password)) {
$query = 'SELECT Email, Password FROM tblregpersons
WHERE Email="' . $login_email . '"
AND Password="' . $login_password . '"';
if ($query_run = mysql_query($query)) {
$query_num_rows = mysql_num_rows($query_run);
if ($query_num_rows == 0) {
echo "invalid";
}
else {
$_SESSION['email'] = $_POST['login_email'];
header('location: index.php?page=succes');
exit();
***// This redirect doesn't work. The page stays on logincheck.php.***
}
}
else {
echo "query failed";
}
}
else {
echo "Please fill in an email/password";
}
}
else {
echo "no post";
}
else {
"U are already logged in";
}
?>
我使用$_SESSION['email']
,因为我也有一个注册表单,并且我将此“电子邮件”会话链接到注册和登录表单的 POST。
我在这个重定向中做错了什么?