私はPHPに少し慣れていないので、ログインフォームで次のことをしようとしています: - index.php: ログイン (reglogin.phpへのリンク) - reglogin.php: 登録またはログインのいずれか。ログイン時: 電子メールがデータベースにあるかどうかを確認します。その場合 --> ログインして成功ページに移動します。成功ページへのリダイレクトが機能しません。
index.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>
include/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>
Reglogin.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"; } ?>
Logincheck.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 にリンクしています。
このリダイレクトで何が間違っていますか?