登录重定向是登录被接受

时间:2016-03-03 22:56:44

标签: php

这是登录页面代码。在我插入正确的登录后,页面不会将我重定向到" customer_account_summary.php"。该页面只是刷新并要求我再次登录。但如果我访问" customer_account_summary.php"手动我可以告诉它已成功登录。

    $sql="SELECT email,password FROM customer WHERE email='$username' AND password='$password'";
$result=mysql_query($sql) or die(mysql_error());
$rws=  mysql_fetch_array($result);

$user=$rws[0];
$pwd=$rws[1];    

if($user==$username && $pwd==$password){
    session_start();
    $_SESSION['customer_login']=1;
    $_SESSION['cust_id']=$username;
header('location:customer_account_summary.php'); 
die();  
}
else{
    header('location:index.php');  
}}
?>
<?php 
session_start();

if(isset($_SESSION['customer_login'])) 
    header('location:customer_account_summary.php'); 

?>

这是登录表html

        <div class="user_login">
        <form action='' method='POST'>
    <table align="left">
        <tr><td><span class="caption">Secure Login</span></td></tr>
        <tr><td colspan="2"><hr></td></tr>
        <tr><td>Username:</td></tr>
        <tr><td><input type="text" name="uname" required></td> </tr>
        <tr><td>Password:</td></tr>
        <tr><td><input type="password" name="pwd" required></td></tr>

        <tr><td class="button1"><input type="submit" name="submitBtn" value="Log In" class="button"></td></tr>
    </table>
            </form>
        </div>

1 个答案:

答案 0 :(得分:1)

设置标头重定向后,需要停止脚本执行。

header('Location: /customer_account_summary.php'); 
die(); // <-- important!