-3

我是 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.";
    }
    ?>
4

2 回答 2

0

在脚本顶部使用以下内容,您的页面现在将显示有关问题的所有信息 =)

有了这些信息,其他人可以更轻松地帮助你,它会帮助你学习/发现你的错误

ini_set('display_errors', true);
error_reporting(-1);
于 2013-06-28T11:27:11.897 回答
0

您缺少一些花括号。不确定这是否是您的问题的原因,但请尝试一下。添加的第三行和第四行将错误报告设置为显示在当前页面上,而不是将其记录到文件/syslog/等。

<?php
session_start();
ini_set('display_errors', true);
error_reporting(E_ALL);

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) {
            session_regenerate_id();
            $_SESSION['username']=':username';
            $_SESSION['password']=':password';

            header('Location: index.php');
        } else {
            $notifications[] = "Username or Password incorrect.";
        }
    }
}
?>
于 2013-06-28T11:47:36.360 回答