我花了几个月的时间在我的电脑上创建了一个本地网站。我现在已经购买了一个域名,并上传了我的文件和数据库。
由于某种我想不起来的原因,用户不能再登录网站了——我也用UK2.net检查了我的登录凭据,他们说他们都是正确的。
可能出了什么问题?
登录表单:
<form action="login.php" method="post" >
Email<br />
<input name="email" type="text" /><br /><br />
Password<br />
<input name="password" type="password" /><br />
<input name="submit" type="submit" value="Log In" />
</form>
登录PHP:
require_once('/scripts/includePDO.php');
$error = '';
$form = $_POST['submit'];
$email = $_POST['email'];
$password = $_POST['password'];
if( isset($form) ) {
if( isset($email) && isset($password) && $email !== '' && $password !== '' ) {
$sql = "SELECT * FROM tbl_users WHERE email = :email and password = :password";
$q = $conn->prepare($sql); // the default way of PDO to manage errors is quite the same as `or die()` so no need for that
$q->bindValue(':email',$email,PDO::PARAM_STR);
$q->bindValue(':password',$password,PDO::PARAM_STR);
$q->execute();
$r = $q->fetch(PDO::FETCH_ASSOC);
if(($r)!=0)
{ //success
$answer = $r['id'];
$_SESSION['logged-in'] = true;
$_SESSION['who'] = $answer;
//If the login details are entered and they match those in the database, forward to new page.
header('Location: /home/');
exit;
// If information is wrong or missing, provide error message.
} else { echo "Sorry, something hasn't worked. Are you entering all the information correctly?"; }
}
}
答案是-
在scripts/includePDO.php之前有一个斜杠,这个斜杠不需要在那里,这使得无法找到该文件