我是 php 新手,我需要有关此代码的帮助,因为当我尝试加载它时,我得到“HTTP-fout 500(内部服务器错误):”。有人可以发布整个好的代码。谢谢。
<?php
session_start();
if(empty($_POST['username']) || empty($_POST['password'])) {
$notifications[] = 'Login failed! Please provide a username and password.';
}
if(count($notifications) == 0) {
try {
$dbh = new PDO('mysql:dbname=####;host=####',
'####', '####');
$sql = "SELECT username, verified FROM users WHERE username = :username AND
password = :password";
$sth = $dbh->prepare($sql);
$sth->execute(array(
':username' => $_POST['username'],
':password' => md5($_POST['password'])
));
$result = $sth->fetch(PDO::FETCH_ASSOC);
if($result) {
// Set session details and redirect user to members page
session_regenerate_id();
$_SESSION['username']=':username';
$_SESSION['password']=':password';
header('Location: index.php');
} else {
$notifications[] = "Username or Password incorrect.";
}
?>