[RESOLVED] More info possible in error logs?
Results 1 to 8 of 8

Thread: [RESOLVED] More info possible in error logs?

  1. #1
    Senior Member
    Join Date
    Sep 2003
    Posts
    122

    resolved [RESOLVED] More info possible in error logs?

    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).

    Thanks!

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,429
    Quote Originally Posted by sois View Post
    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.



    Quote Originally Posted by sois View Post
    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)?

    Quote Originally Posted by sois View Post
    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.

    Quote Originally Posted by sois View Post
    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?

  3. #3
    Senior Member
    Join Date
    Sep 2003
    Posts
    122
    lines 1-38:

    PHP Code:
    <?php
    require_once('includes/master-include.php');

    // Variable Validation
    $v = new Validator();
    $v->ExistsInTable('League Id'$_GET['league'], 'teams''League_Id');
    $v->ExistsInTable('Player Id'$_GET['player'], 'players''Player_Id');
    $v->IsNumeric('League Id'$_GET['league'], 1NULL);
    if (
    $v->error_counter 0) {
        
    header("Location: http://www.leaguestatbook.com/");
    }

    // 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']);

    // Page Pretty Stuff
    $page = new Page($league);
    $page->PageHeader($player_info['Player_First'] . ' ' $player_info['Player_Last']);
    $page->Banner();
    $page->Menu();
    $page->StartContent();


    // Top Main Info Little Table
    echo '<table width="650" style="margin-left: auto; margin-right: auto;">';
    if (
    file_exists('/home/sois/public_html/leaguestatbook/engine/images/headshots/' $_GET['player'] . '.png')) echo '<tr><td width="65"><img src="images/headshots/' $_GET['player'] . '.png"></td>';
    else echo 
    '<tr><td width="65"><img src="images/headshots/none.png"></td>';
    echo 
    '<td>';
    echo 
    '<h1>' $player_info['Player_First'] . ' ' $player_info['Player_Last'] . '</h1>';
    echo 
    '<span>' $player_info['Team_Name'] . ' #' $player_info['Player_Jersey'] . '</span>'
    echo 
    '</td></tr>';
    echo 
    '</table>';

  4. #4
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,429
    So in each of these statements:

    PHP Code:
    $v->ExistsInTable('League Id'$_GET['league'], 'teams''League_Id'); 
    $v->ExistsInTable('Player Id'$_GET['player'], 'players''Player_Id'); 
    $v->IsNumeric('League Id'$_GET['league'], 1NULL);

    // ...

    $league = new League($_GET['league']); 
    $player = new Player($_GET['player']);

    // ...

    $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.

  5. #5
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    13,949
    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


    eBookworm.us

  6. #6
    Senior Member
    Join Date
    Sep 2003
    Posts
    122
    Quote Originally Posted by bradgrafelman View Post
    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.

    Quote Originally Posted by NogDog View Post
    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.)
    Thanks, I'll look into that!

  7. #7
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,889
    Quote Originally Posted by sois
    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.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  8. #8
    Senior Member
    Join Date
    Sep 2003
    Posts
    122
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •