PHP身份验证仅适用于本地

I have a PHP login page that works perfectly locally, but when in server always come out with "Invalid Username or Password". I tried it in two different servers and the result was the same.

login.php

session_start(); // Starting Session
$error = ''; // Variable To Store Error Message

if (isset($_POST['submit'])) {
    if (empty($_POST['username']) || empty($_POST['password'])) 
    {
        $error = "Username or Password is invalid";
    }
    else
    {
        // Define $username1 and $password1
        $username1 = $_POST['username'];
        $password1 = $_POST['password'];

        include_once ('lib/db.php');
        $connection = new mysqli($servername, $username, $password, $dbname);

        $username1 = stripslashes($username1);
        $password1 = stripslashes($password1);
        $username1 = mysql_real_escape_string($username1);
        $password1 = mysql_real_escape_string($password1);


        // SQL query to fetch information of registerd users and finds user match.
        $query = "select * from login where PASSWORD='$password1' AND USERNAME='$username1'";
        $result = $connection->query($query);
        $rows = mysqli_num_rows($result);

        if ($rows == 1) 
        {
            $_SESSION['user']=$username1; // Initializing Session
            $_SESSION['pppv'] = 10;
            header("Location: logged-in.php"); // Redirecting To Other Page
        } 
        else 
        {
            $error = "Username or Password is invalid";
        }

    }
}

EDIT

Try printing the query after submission gives me this:

Local:

select * from login where PASSWORD='test' AND USERNAME='test'

Server:

select * from login where PASSWORD='' AND USERNAME=''

Use isset($_POST['username']) ||isset($_POST['password'])instead of empty($_POST['username']) || empty($_POST['password']).

Read this to know the difference between isset and empty.

There's no context, but check these things:

  • Does your database contain the same credentials as local?
  • Does your requested page return http status such as 200? If it's 404, there's something wrong with your path's. If it's 500, there's an internal error (right permissions set?)
  • Did you check your log files?
  • Did you clear your browser cookies and history?
  • Did you print the full query (including filled parameters) to the window and did you execute this query in your database management tool? And did you get result?