login.php
-它检查输入的用户名是否存在于数据库中,然后比较输入的密码和数据库中的密码是否匹配,并将这些操作的结果打印在网页上(目前)。
首先登录页面:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once("scripts/config.php");
require_once("scripts/helperClass.php");
$username = strip_tags($_POST["username"]);
$password = strip_tags($_POST["password"]);
echo helperClass::checkCredentials($username, $password);
?>
现在helper类:(或者至少是相关函数):
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class helperClass {
public static function checkCredentials($UserName, $Password) {
try {
$pdo = new PDO("mysql:host=".mydbhost.";dbname=".mydbname, myuname, mydbpw);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $ex) {
throw(new PDOException($ex->getMessage(), (int) $ex->getCode()));
}
$statement = $pdo->prepare("SELECT UserId, Password FROM ChatUsers WHERE (? = UserName) OR (? = E_Mail)");
$statement->execute(array($UserName, $UserName));
$foundUser = $statement->fetch(PDO::FETCH_ASSOC);
if($foundUser) {
$pwCorrect = $foundUser["Password"] == $Password;
if(pwCorrect) {
$statement = $pdo->prepare("UPDATE ChatUsers SET LoggedIn = true WHERE ? = UserId");
$statement->execute(array($foundUser["UserId"]));
return true;
}
else {
return false;
}
}
else {
return false;
}
}
}
?>
在
config.php
我定义实际的连接数据。它在本地编译得很好,但最终与
PDOException
因为请求超时。(我的PHP编辑器支持pDO,因此即使本地连接到外部数据库也可以工作)。在网上我看到了死亡的白屏。
我现在实现了错误显示,并且可以看到它正在工作,因为我收到了以前没有提示的额外通知。从登录页加载的时间来看,SQL查询得到执行,但是页面仍然是空白的,没有错误,没有返回。还有什么我忽略的吗?