What error messaging could I insert into this script to find out the problem

允我心安 提交于 2019-12-31 06:13:30

问题


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>

回答1:


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.



来源:https://stackoverflow.com/questions/5830260/what-error-messaging-could-i-insert-into-this-script-to-find-out-the-problem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!