I'm trying to construct a script - login.php
- which checks whether the entered username exists in the database, then compares whether entered password and password in the database match and is supposed to print the result of these operations on the web page (for now).
First of all the login page:
<?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);
?>
Now the helper class: (or at least the relevant function):
<?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;
}
}
}
?>
In config.php
I define the actual connection data. It compiles fine locally, but then eventually crashes with a PDOException
as the request timed out. (My PHP editor has pDO support so even locally connection to the external database should work). Online I just get a white screen of death.
I implemented error displaying now, and can see it's working as I get extra notices which were previously silent. Judging from the time the login page takes to load, the SQL query gets executed, but the page still is blank, no errors, no return. Is there anything else I overlooked?