php die()不起作用(只是代码)

时间:2012-08-09 03:45:24

标签: php

我正在学习如何使用“setcookie”,但是,我无法使用以下工作线, 我在这里粘贴了所有代码,如果有人可以请我帮忙吗? 不知道原因。 非常感谢。

  else{ die ("hahahahahahahahahahahahahaha"); }

HTML代码

<form method="POST" action="">
<div class="error"><?php echo $error;?></div>
<p></p>
<label>Username: </label><br>
<input type="text" name="username"><br>
<label>Password: </label><br>
<input type="password" name="password"><br>
<input type="checkbox" name="rememberme"> Remember me<br>
<input type="submit" name="submit" value="Login">

PHP代码

<?
if(isset($_POST['submit'])){
    //get data
    $username = $_POST['username'];
    $password = $_POST['password'];
    $rememberme = isset($_POST['rememberme']);
    echo $rememberme;


    if($username&&$password){
    $login = mysql_query("SELECT * FROM form WHERE username='$username'");

    while ($row = mysql_fetch_assoc($login))
    {
        $db_password = $row['password'];
        if (md5($password)== $db_password)
        {
            $logstatus = TRUE;
            }
        else{
            $logstatus = FALSE; 
            }
        if ($logstatus == TRUE)
        {
            if ($rememberme == "1")
                setcookie("username", $username, time()+600);
            else if ($rememberme == "")
                $_SESSION['username'] = $username;


        echo " I am here";
        }

        else{
           die ("hahahahahahahahahahahahahaha"); //unable to get here
        }
    }

}

    else{
    echo "enter username / password";
    }
}
?>

3 个答案:

答案 0 :(得分:0)

试试这段代码,我还没有测试过,但它应该可行:)

session_start();//dont forget this :P
if(isset($_POST['submit'])){
    //get data
    $username = $_POST['username'];
    $password = $_POST['password'];
    $rememberme = isset($_POST['rememberme']);
    echo $rememberme;    
if($username&&$password){
    $login = mysql_query("SELECT * FROM form WHERE username='$username' AND password='".md5($password)."'");


        if (mysql_num_rows($login))//if this returns 1 you are logged in
        {
            if ($rememberme == "1")
                setcookie("username", $username, time()+600);
            else
                $_SESSION['username'] = $username;


                echo " I am here";              

        }else{
           die ("Incorrect Username/Password"); //unable to get here
        }
    }

}

    else{
    echo "enter username / password";
    }
}

答案 1 :(得分:-1)

while循环导致问题,只需删除它。

答案 2 :(得分:-1)

嗯,我没有测试过代码,但尝试以下内容可能有所帮助。

添加行:

$logstatus = TRUE;

之前。

理由: 块完成后,变量的范围完成。在外部定义logstatus,同时确保其范围不会在需要的地方结束。