Odd error logs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hampster
Forum Newbie
Posts: 2
Joined: Fri Dec 03, 2004 1:56 am
Contact:

Odd error logs

Post by Hampster »

Well, my program is working fine. Or so I thought. I checked my Apache error logs one day, and found the following:

Code: Select all

їThu Dec  2 23:44:45 2004] їerror] PHP Notice:  Use of undefined constant userName - assumed 'userName' in /Library/WebServer/Documents/C-n-R/index.php on line 5
їThu Dec  2 23:44:46 2004] їerror] PHP Notice:  Use of undefined constant userPass - assumed 'userPass' in /Library/WebServer/Documents/C-n-R/index.php on line 6
etc, etc.

My program is a simple front end to a MySql database, and uses sessions to keep track of who you are and what your password is. Here are the first few lines of my index.html file:

Code: Select all

<?
	session_name("C-n-R-DB");
	session_start();
	
	$_SESSION[userName]="Assistant"; // User name
	$_SESSION[userPass]="";    // User Password
(The username gets changed when pulled from a drop down list.)

This may be a case of "if it ain't broke, don't fix it," but I am a bit of a purist. Are these Apache error messages something I should worry about? Is there something wrong with the way I set up my session?

Any thoughts would be appreciated.

-Dave
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

you need to do

$_SESSION['userName']

omitting the quotes is whats casuing your problem, unless of course, userName was a constant. but its not, hence the error :)

oh, and they are php error messages, not apache

this particular notice isnt really anything to worry about, but it could be considered sloppy coding.

try developing w/ error reporting set high, then php will spit those and all other notices and errors out at you so you can see them

error_reporting(E_ALL);

and if using php5, they have a special "purist" setting too

error_reporting(E_STRICT);
Hampster
Forum Newbie
Posts: 2
Joined: Fri Dec 03, 2004 1:56 am
Contact:

Post by Hampster »

Thanks. I do realize is was a php code, but I saw them through the Apache error logs. Is there another place to look for just php error messages?

the error_reporting(E_STRICT); I take it that is on a per script basis, I probably shouldn't modify the ini file, right?

Finally, I understand why BBEdits multifile search and repace with GREP is so popular.........

Thanls for the tip.

-Dave
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

Hampster wrote: Is there another place to look for just php error messages?

not unless you set up your own custom error_handler in php to log the errors to the file of your choice/ email etc....

Hampster wrote: the error_reporting(E_STRICT); I take it that is on a per script basis, I probably shouldn't modify the ini file, right?

Finally, I understand why BBEdits multifile search and repace with GREP is so popular.........

Thanls for the tip.

-Dave

heres another tip



you could use a config file to do this. doing a global file search and replace works too, but i think it is slightly error prone, if you ever forget to update something. this way, you can have the same version on the server as your local dev box, and have them behave different



Code: Select all

<?php

if ($_SERVER['SERVER_NAME'] == 'localhost') {
    // do your config for development
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    define ('TO_EMAIL', 'admin@localhost');
} else {
    // do your config for the live site
    ini_set('display_errors', 0);
    define ('TO_EMAIL', 'foo@bar.com');
}





?>

then either manually include the file at the top of each script

require_once('includes/config.php');


or use the auto prepend feature in htaccess

Code: Select all

php_value auto_prepend_file "/path/to/your/config.php"
Post Reply