php登录脚本没有重定向到下一页

时间:2016-07-17 18:34:41

标签: php

我的login.php如下所示,它无法接受welcome.php。它都没有给出登录错误。它只是给出500错误页面。

<?php
include("db.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from Form
$username=mysqli_real_escape_string($db,$_POST['username']);
$password=mysqli_real_escape_string($db,$_POST['password']);
$password=md5($password); // Encrypted Password
$sql="SELECT id FROM admin WHERE username='$username' and passcode='$password'";
$result=mysqli_query($db,$sql);
$count=mysqli_num_rows($db,$result);

// If result matched $username and $password, table row must be 1 row
if($count==1)
{
header("location: welcome.php");
}
else
{
$error="Your Login Name or Password is invalid";
}
}
?>
  <div class="wrapper">
    <form class="form-signin" action="login.php" method="post">       
      <h2 class="form-signin-heading">Please login</h2>
      <input type="text" class="form-control" name="username" placeholder="User Name" required="" autofocus="" />
</br> 
      <input type="password" class="form-control" name="password" placeholder="Password" required=""/>    
      <label class="checkbox">
        <input type="checkbox" value="remember-me" id="rememberMe" name="rememberMe"> Remember me
      </label>
      <button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>   
    </form>
  </div>

提交用户名和密码后,它给出了500错误,无法将我带到welcome.php。

1 个答案:

答案 0 :(得分:1)

如果您正在使用标题(位置:something.php),则应将其作为php中的第一个输出加载。否则它将无法正常工作。

session_start()将更改HTTP标头。

而是尝试低于一,

echo "<script>window.location.href='welcome.php';</script>";
相关问题