我可以在该脚本中插入什么错误消息来找出问题

发布于 2024-11-04 05:26:45 字数 2359 浏览 2 评论 0原文

我正在读 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>

I'm reading a book called PHP 5 Advanced Techniques by Larry Ullman.

In Chapter 4, he introduces us to PEAR. After a long struggle I managed to get PEAR working with MAMP and installed the Auth and MDB2 package required for this authentication code. However, when I run it, I'm getting this server errror

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.

Is there any kind of debugging I can insert into the code to figure out what the problem is? I'm a bit of a newbie so detailed instructions would be very helpful.

<?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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

左岸枫 2024-11-11 05:26:45

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

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

Enable display_errors in your php.ini so you get the actual error message.

If it still doesn't work, enable log_errors so your script's errors are sent to a file or syslog.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文