Is it possible to get more information from the error logs? I would like to get the referral URL and the page URL at the time the error was caused as well as the error. Here is an example of what I currently get:
Code:
[08-Feb-2013 22:31:17] PHP Notice: Undefined index: Player_Last in /home/sois/public_html/leaguestatbook/engine/player.php on line 34
[08-Feb-2013 22:31:17] PHP Notice: Undefined index: Team_Name in /home/sois/public_html/leaguestatbook/engine/player.php on line 35
[08-Feb-2013 22:31:17] PHP Notice: Undefined index: Player_Jersey in /home/sois/public_html/leaguestatbook/engine/player.php on line 35
[09-Feb-2013 05:06:08] PHP Notice: Undefined offset: 0 in /home/sois/public_html/leaguestatbook/engine/team.php on line 34
[09-Feb-2013 05:06:08] PHP Notice: Undefined offset: 0 in /home/sois/public_html/leaguestatbook/engine/team.php on line 35
[09-Feb-2013 05:06:08] PHP Notice: Undefined offset: 0 in /home/sois/public_html/leaguestatbook/engine/team.php on line 37
My pages have code to validate those errors, but for some reason, they are still popping up. I want to know how people are getting to this page in the first place and where they are coming from if possible. Is this information available to be added to the log?
I have messed with the error_log() function, but that replaces the current information, not adds to it. Maybe I'm just doing it wrong. I'd like the current info as well as $_SERVER['REQUEST_URI'] as well as the referrer variable (I don't remember what that is off the top of my head).
Is it possible to get more information from the error logs? I would like to get the referral URL and the page URL at the time the error was caused as well as the error.
You might able to get that information from your webserver's access logs by correlating the exact time of the error messages, but if you had multiple visitors at that time, then there's going to be some assumption/guesswork involved.
Originally Posted by sois
My pages have code to validate those errors, but for some reason, they are still popping up.
Can you show us this player.php script (e.g. lines 1-38 or so)?
Originally Posted by sois
I want to know how people are getting to this page in the first place and where they are coming from if possible. Is this information available to be added to the log?
See above. Note that you could detect the error conditions and add manual error log entries to record any information you want. However, note that the 'Referer' HTTP header is not required and can even be faked or stripped out altogether by the user's browser or an intermediate gateway.
Originally Posted by sois
I have messed with the error_log() function, but that replaces the current information, not adds to it. Maybe I'm just doing it wrong.
I'd go with that last statement since error_log() will simply "send an error message somewhere." Can you show us an example of the script where you tried to use it?
// Objects needed for this page.
$league = new League($_GET['league']);
$player = new Player($_GET['player']);
// Object functions to run (makes overhead smaller doing it this way)
$player_info = $player->PlayerInformation();
$stats = $player->PlayerStatsTable($_GET['player'], $_GET['league']);
if (file_exists('/home/sois/public_html/leaguestatbook/engine/images/headshots/' . $_GET['player'] . '.png'))
you're referencing external variables without first checking that they actually exist (e.g. via isset(), empty(), array_key_exists(), etc.). If they don't, you'll see the error messages you posted above.
You could do something with set_error_handler() to output whatever you want in the error log, perhaps. (Just read the manual page carefully to realize that there are certain error types that it won't handle, but it should be okay for those notice-level errors you're currently concerned with.)
Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett
"But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because he’s a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html
So in each of these statements:
ou're referencing external variables without first checking that they actually exist (e.g. via isset(), empty(), array_key_exists(), etc.). If they don't, you'll see the error messages you posted above.
Hmm, that's odd. I figured if they didn't exist, they would be instantiated on the fly. I guess they used to do that. Maybe my php version changed? Hmm. I guess I will have to re-write all pages with $_GET variables to even make sure they exist in the first place.
Originally Posted by NogDog
You could do something with set_error_handler() to output whatever you want in the error log, perhaps. (Just read the manual page carefully to realize that there are certain error types that it won't handle, but it should be okay for those notice-level errors you're currently concerned with.)
Hmm, that's odd. I figured if they didn't exist, they would be instantiated on the fly. I guess they used to do that. Maybe my php version changed?
That has been PHP's behaviour for a very long time now (at least, I don't remember when it wasn't); more likely you just had reporting of Notices turned off until recently.
I checked my config file, I had E_ALL error reporting. I don't know why this is suddenly popping up though. I think I will just practice better coding and initialize those variables. Thanks all! Closed.
Bookmarks