我可以在此脚本中插入哪些错误消息以找出问题

时间:2011-04-29 09:18:19

标签: php pear

我正在阅读Larry Ullman撰写的一本名为PHP 5 Advanced Techniques的书。

在第4章中,他向我们介绍了PEAR。经过长时间的努力,我设法让PEAR与MAMP合作并安装了此身份验证代码所需的Auth和MDB2包。但是,当我运行它时,我得到的服务器错误

The website encountered an error while retrieving http://localhost:8888/phpvqp2_scripts/Ch04/login.php. It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this web page later.

我可以在代码中插入任何类型的调试来找出问题所在吗?我是一个新手,所以详细的说明会非常有帮助。

<?php # Script 4.3 - login.php

/*  This page uses PEAR Auth to control access.
 *  This assumes a database called "auth",
 *  accessible to a MySQL user of "root@localhost" 
 *  with a password of "root".
 *  Table definition:

    CREATE TABLE auth (
    username VARCHAR(50) default '' NOT NULL,
    password VARCHAR(32) default '' NOT NULL,
    PRIMARY KEY (username),
    KEY (password)
    )
 *  MD5() is used to encrypt the passwords.
 */

// Need the PEAR class:
require_once ('Auth.php');

// Function for showing a login form:
function show_login_form() {

    echo '<form method="post" action="login.php">
<p>Username <input type="text" name="username" /></p>
<p>Password <input type="password" name="password" /></p>
<input type="submit" value="Login" />
</form><br />
';

} // End of show_login_form() function.

// Connect to the database: 
$options = array('dsn' => 'mysql://root:root@localhost/auth');

// Create the Auth object:
$auth = new Auth('DB', $options, 'show_login_form');

// Add a new user:
$auth->addUser('me', 'mypass');

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Restricted Page</title>
</head>
<body>
<?php

// Start the authorization:
$auth->start();

// Confirm authorization:
if ($auth->checkAuth()) {

    echo '<p>You are logged in and can read this. How cool is that?</p>';

} else { // Unauthorized.

    echo '<p>You must be logged in to access this page.</p>';

}

?>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

在php.ini中启用display_errors,以便获得实际的错误消息。

如果仍然无效,请启用log_errors,以便将脚本的错误发送到文件或系统日志。