带有帐户激活检查的PHP登录页面

时间:2015-11-28 04:08:19

标签: php session login activation

我正在尝试编写一个登录页面,只有在用户激活了帐户时才会记录用户。如果他们尚未激活,则应将其重定向到激活页面。我不明白为什么我的脚本不工作,它只显示“用户名是必需的”错误消息。我认为我的if语句可能有误? user.php是成功登录后应该访问的用户配置文件 activation.php是他们激活帐户的地方。

    <body>
<?php

if ($_POST['submit']){
 $getuser=$_POST['uname'];
 $getpass=$_POST['pword'];

if($getuser){
    if($getpass){
            require("./mysql.php");
            $query=mysqli_query($conn,"SELECT * FROM userdet WHERE username='$getuser'&& password='$getpass'");
            $numrows = mysqli_num_rows($query);
            if($numrows==1){
                $row =mysqli_fetch_assoc($query);
                $dbactive=$row['status'];
                if ($dbactive==1){
                    $query=mysqli_query($conn,"SELECT * FROM userdet WHERE username='$getuser'&& password='$getpass' && status='1'");
                    $_SESSION['username']=$getuser;
                    header("Location:user.php");
                }
                else
                    //$errormsg = "Your account has not been activated";
                    header("Location:Activation.php")

            }
            else
                $errormsg="Username not found";
            mysqli_close($conn);
        }
        else
            $errormsg="Password is required";
    }           
    else
        $errormsg="Username is required";
}
else 

    $errormsg="";
echo "<form action='./login.php' method='post' >

<table>
<tr>
    <td> </td>
    <td> $errormsg</td>
</tr>
<tr>
    <td> Username:* </td>
    <td> <input type='text' id='uname' name='username'  value='$getuser' /></td>
</tr>
<tr> 
    <td> Password:* </td>
    <td><input type='password' name='pword' id='code'  value='$getpass' /></td>
<tr> 
    <td></td>
    <td><input type='submit' name='submit' value='Log in' /></td>
</tr>
</tr>
</table>
</form>";


?>
</body>

1 个答案:

答案 0 :(得分:1)

您正在访问的内容存在错误。当您发布表单时,值引用为name而不是id

 $getuser=$_POST['uname'];

应该是

$getuser=$_POST['username'];

正如您在此处name='username'所见,您还可以定义具有相同名称的id,以避免混淆。

<input type='text' id='username' name='username'  value='$getuser' />