我可以在这个脚本中插入什么错误信息来找出问题 [英] What error messaging could I insert into this script to find out the problem

查看:50
本文介绍了我可以在这个脚本中插入什么错误信息来找出问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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>

推荐答案

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

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

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

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

这篇关于我可以在这个脚本中插入什么错误信息来找出问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆