在PHP中成功登录后如何重定向到另一个页面?

时间:2018-09-01 12:09:55

标签: php mysqli

login.php

<?php
    session_start();
    error_reporting(0);
    include("config.php");
    if(isset($_POST['submit']))
    {
        $pass= $_POST['password'];
        $email= $_POST['email'];
        if($email=='' && $pass=='')
        {
            echo '<p id="red">Wrong Email or Password.</p>';
        }
        else
        {
            $query=mysqli_query($con, "select * from `user` where `password`='".$pass."' and `email`='".$email."' and status='1'");
            $countRow=mysqli_num_rows($query);
            $fetch=mysqli_fetch_array($query);
            if($countRow > 0)
            {
                $_SESSION['user_idd']= $fetch['user_id'];
                //$_SESSION['user_idd'];
                header('location:index.php');
            }
            else
            {
                echo '<p id="red">Wrong Email or Password.</p>';
            }
        }
    }
?>
<form method="POST" id="myforms" autocomplete="off" action="<?php echo $_SERVER['PHP_SELF'];?>">
    <input type="text" name="email" value="" placeholder="Enter Your Email" class="form-control">
    <input type="password" name="password" value="" placeholder="Enter Your Password" class="form-control">
    <input type="submit" name="submit" value="Login" class="btn btn-success">   
</form>

index.php

<?php
    session_start();
    error_reporting(0);
    include("config.php");
    if(!isset($_SESSION['user_idd']))
    {
        header("location:login.php");
    }

    echo "hiii";
?>

我创建了简单的登录名,正如您在我的login.php文件中看到的那样。现在,我想在成功后从login.php重定向到index.php页面,但是问题是当我单击“提交”按钮时,它没有在index.php页面上重定向我,它显示了相同的页面,并且当我直接在网址中调用index.php时,它将再次显示login.php。我不知道我在哪里做错了?请帮助我。

谢谢

0 个答案:

没有答案