简体   繁体   English

php重定向页面问题

[英]php redirect page issue

i used php script to login my application.我使用 php 脚本登录我的应用程序。 but it dosen't work well.但效果不佳。 i want to fix this error.我想修复这个错误。 it loads same page.它加载相同的页面。 i want to show if username and email is okay then show index page.i use php code in same login view我想显示用户名和电子邮件是否正常然后显示索引页面。我在同一个登录视图中使用 php 代码

<?php

if(isset($_POST['submit'])){

    $email = $_POST['email'];
    $pass = $_POST['password'];

    $db = new Database();
    $db->query('select email, password from user where email = :email and password = :password');
    $db->bind(':email', $email);
    $db->bind(':password', $pass);
    $db->resultset();
    print_r($db->resultset());

    if($db->rowCount() == 1){

        header('location: index.php');  
    }

}   
?>

and this is my login form in same file这是我在同一个文件中的登录表单

<form method="post" action="" class="form-horizontal">

              <div class="form-group">
                  <h2 style="font-size: 25px; text-align: center; font-weight: 600; margin-bottom: 30px;">LOGIN HERE</h2>
              </div>
              <div class="form-group">                  
              </div>
              <div class="form-group">
                  <label for="email">Email: </label>
                  <input type="email" class="form-control" id="email" name="email" required="require" placeholder="Enter email">   
              </div>
              <div class="form-group">
                  <label for="password">Password</label>
                  <input type="password" class="form-control" id="password" name="password" required="require" placeholder="Enter password">  
              </div>           

              <input type="submit" class="btn btn-primary" name="submit" value="Login"/>
      </form>

Replace the line更换线路

<form method="post" action="" class="form-horizontal">

with

<form method="post" action="#" class="form-horizontal">

or或者

<form method="post" action="yourfilename.php" class="form-horizontal">

or或者

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" class="form-horizontal">

First , that Code would Only run If you Login Details are Found Correct And Matched a Row in a Database首先,该代码仅在您发现登录详细信息正确且与数据库中的一行匹配时才会运行

Second , Kindly Update this Code其次,请更新此代码

'select email, password from user where email = :email and password = :password'

to

"SELECT email, password FROM user WHERE email = '$email' and password = '$password'"

Lastly , header('Location: index.php');最后header('Location: index.php');

I Hope this works...我希望这有效...

Here you go...干得好...

<?php  
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Connection Query
    $db = new Database();
    // Fetch Login Data
    $email = $_POST['email'];
    $pass = $_POST['password'];
    // Login Query
    $login = "SELECT email, password FROM user WHERE email='$email' and password='$pass'";
    // Query SQL
    $req = mysqli_query($db, $login);
    // Check if Row matched is Above Zero
    if (mysqli_num_rows($req) > 0) {
        // Redirect User
        header("Location: index.php");
    }
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM