我有一个在本地完美运行的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";
}
}
}
提交后尝试打印查询给我:
本地:
select * from login where PASSWORD='test' AND USERNAME='test'
服务器:
select * from login where PASSWORD='' AND USERNAME=''
答案 0 :(得分:0)
使用isset($_POST['username']) ||isset($_POST['password'])
代替empty($_POST['username']) || empty($_POST['password'])
。
阅读this,了解isset
和empty
之间的区别。
答案 1 :(得分:0)
没有上下文,但请检查以下内容: