Author: Rifkin, Jonathan

PHP Debugging: Displaying Error Message in HTML output

When debugging PHP code, it can be useful to display PHP errors within the output. Normally, PHP error messages are written to the Apache log.

To have PHP errors in your browser output, you can use this command in your PHP script

ini_set(‘display_errors’, 1);

Below is a short example PHP script that demonstrates.

<?php
print “The following include fails quietly.<br/>n”;
include(“first_missing.inc”);
print “After first failed include.<br/>n”;
print “——<br/>n”;
print  “Now we switch on display_errors.<br/>n”;
ini_set(‘display_errors’, 1);
print “——<br/>n”;
print “Now, the second include fails with following error messages.<br/>n”;
print “<br/><i>n”;
include(“second_missing.inc”);
print “</i><br/><br/><br/>n”;
print “After second failed include.<br/>n”;
?>

And here is the output from the script.

The following include fails quietly.
After first failed include.
——
Now we switch on display_errors.
——
Now, the second include fails with following error messages.

Warning: include(): Unable to access second_missing.inc in /export/www/sites/testsite/error3.php on line 19  Warning: include(second_missing.inc): failed to open stream: No such file or directory in /export/www/sites/testsite/error3.php on line 19 Warning: include(): Failed opening ‘second_missing.inc’ for inclusion (include_path=’.:/usr/share/php:/usr/share/pear’) in /export/www/sites/testsite/error3.php on line 19

After second failed include.

PHP Debugging: Displaying Error Message in HTML output

When debugging PHP code, it can be useful to display PHP errors within the output. Normally, PHP error messages are written to the Apache log.

To have PHP errors in your browser output, you can use this command in your PHP script

ini_set(‘display_errors’, 1);

Below is a short example PHP script that demonstrates.

<?php
print “The following include fails quietly.<br/>n”;
include(“first_missing.inc”);
print “After first failed include.<br/>n”;
print “——<br/>n”;
print  “Now we switch on display_errors.<br/>n”;
ini_set(‘display_errors’, 1);
print “——<br/>n”;
print “Now, the second include fails with following error messages.<br/>n”;
print “<br/><i>n”;
include(“second_missing.inc”);
print “</i><br/><br/><br/>n”;
print “After second failed include.<br/>n”;
?>

And here is the output from the script.

The following include fails quietly.
After first failed include.
——
Now we switch on display_errors.
——
Now, the second include fails with following error messages.

Warning: include(): Unable to access second_missing.inc in /export/www/sites/testsite/error3.php on line 19  Warning: include(second_missing.inc): failed to open stream: No such file or directory in /export/www/sites/testsite/error3.php on line 19 Warning: include(): Failed opening ‘second_missing.inc’ for inclusion (include_path=’.:/usr/share/php:/usr/share/pear’) in /export/www/sites/testsite/error3.php on line 19

After second failed include.

Starting Google Apps and GAM (Google Apps Manager)

GAM is a command-line tool for manipulating Google Apps accounts. It is written in Python, and uses Google’s gdata Python module.

GAM is documented at http://code.google.com/p/google-apps-manager/. The gdata Python module is documented at http://code.google.com/p/gdata-python-client/.

Installing GAM
When you install GAM, it installs the gam.py Python script, and the gdata module in its own directory. See instructions on the GAM page linked above.

Configuring GAM
To use GAM, you need to configured it to use your Google Apps Management credentials. This involves running this on the command-line;

python gam.py info domain

This will guide you through the process, during which your web browser will open to a page on Google Apps where you can verify certain information. The link to GAM above explains the details. Once you have authenticated, a credentials file called oauth.txt is created in the current directory. Future invocations of python gam.py will automatically load and use the credentials in oauth.txt.

Using GAM
Once you have configured gam.py to automatically authenticate when run, you can run gam.py with a number of parameters. For example, to get information on the user joe.user, you could do this

python gam.py info user joe.user@uconn.edu

and see something like this

User: joe.user
First Name: Joe
Last Name: User
Is an admin: false
Has agreed to terms: true
IP Whitelisted: false
Account Suspended: false
Must Change Password: false
Email Aliases (Nicknames):
Groups:

Starting Google Apps and GAM (Google Apps Manager)

GAM is a command-line tool for manipulating Google Apps accounts. It is written in Python, and uses Google’s gdata Python module.

GAM is documented at http://code.google.com/p/google-apps-manager/. The gdata Python module is documented at http://code.google.com/p/gdata-python-client/.

Installing GAM
When you install GAM, it installs the gam.py Python script, and the gdata module in its own directory. See instructions on the GAM page linked above.

Configuring GAM
To use GAM, you need to configured it to use your Google Apps Management credentials. This involves running this on the command-line;

python gam.py info domain

This will guide you through the process, during which your web browser will open to a page on Google Apps where you can verify certain information. The link to GAM above explains the details. Once you have authenticated, a credentials file called oauth.txt is created in the current directory. Future invocations of python gam.py will automatically load and use the credentials in oauth.txt.

Using GAM
Once you have configured gam.py to automatically authenticate when run, you can run gam.py with a number of parameters. For example, to get information on the user joe.user, you could do this

python gam.py info user joe.user@uconn.edu

and see something like this

User: joe.user
First Name: Joe
Last Name: User
Is an admin: false
Has agreed to terms: true
IP Whitelisted: false
Account Suspended: false
Must Change Password: false
Email Aliases (Nicknames):
Groups:

Quotes

Debugging is twice as hard as writing the code in the first place.  Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.  — Brian W. Kernighan

 

Object-oriented programming is an exceptionally bad idea which could only have originated in California. — Edsger Dijkstra

 

The whole problem with the world is that fools and fanatics are always so certain of themselves, and wiser people so full of doubts. — Bertrand Russell