Web Hosting Forums

Results 1 to 7 of 7

This is a discussion on php custom 404 page in the Hosting Talk & Chit-chat forum
...

  1. #1
    Loyal Client
    Join Date
    Dec 2001
    Posts
    26

    php custom 404 page

    I've made a custom 404 page with a 404.php file. It uses mail() to send me the follow info.

    REMOTE_ADDR (IP)= just in case it 'might' help trace some friends ? ? ?

    HTTP_REFERER = to see if someone has a dead link to one of my obsolete pages.

    HTTP_USER_AGENT = just curious

    SERVER_NAME = because I use the same 404.php page on 3 different domains / servers. This way my mail notice shows me which domain they hit and I don't have to keep 3 different versions of the .php file.

    ----------
    My problem is that I've tested all the getenv() variables and I can't get the .php file to send me the URL that the visitor was trying to find. Currently I have to go into the access_logs to find out what people were looking for. BTW: at least 4 or 5 a night are looking for cmd.exe

    Is there someway to mail the URL they were looking for?

    BTW: I've tried every getenv() variable in a temp.php file and the ones that 'sound' like they will work only display path info not the actual file / folder that was entered

    TIA

    John

  2. #2
    Loyal Client
    Join Date
    Dec 2001
    Posts
    26

    I can't read:

    I found a way
    I kept playing with all the variables and finally figured out that I had a typo. I should have used

    $requri = getenv ("REQUEST_URI");

    I was reading it as request_URL (and it should have been an 'i' not an 'L' - so simple = stupid. But I was putting $requrl = getenv ("REQUEST_URL"); - which is wrong wrong wrong

    Anyway the env. variable = request_uri .. works. It shows the subdirectories and then the file name. If you combine it with the server_name you get the full path they used.

    So I just wasted space in here due to the fact I can't tell an 'i' from an 'l' :bawl:

    John

  3. #3
    Loyal Client jkeller's Avatar
    Join Date
    Feb 2002
    Location
    Paris, France
    Posts
    1,502

    Re: I can't read:

    Originally posted by princeje
    So I just wasted space in here due to the fact I can't tell an 'i' from an 'l' :bawl:
    Not at all. Not only have you cleared it up for someone else who might be looking, you've also brought up a pretty cool idea: e-mail notification when a visitor gets a 404. Not everyone likes to look at their logs, so this is a pretty clever way to ensure that a site owner gets informed of bad requests.

    P.S. it's "URI" because a "URL" is the address of a file, whereas the "uniform resource indicator" includes parameters and encompasses non-location concepts (such as an e-mail address). Hence the generic (and seemingly odd) name for the environment variable.

  4. #4
    Loyal Client
    Join Date
    Dec 2001
    Posts
    26

    Footnote about URI

    Today the URI variable in my 404 page showed that someone looked to see if I had formail.pl or formail.cgi in my cgi-bin directory. Since I don't, they got my error page and I got the info shown below:
    =======
    URI = /cgi-local/[email protected]&sub ject=www.ibdprince.com/cgi-local/formmail.pl&[email protected] &= www.ibdprince.com/cgi-local/formmail


    /cgi-bin/[email protected]&sub ject= www.ibdprince.com/cgi-bin/formmail.pl& [email protected]&=www.ibdprince.com/cgi-bin/formmail.


  5. #5
    Loyal Client
    Join Date
    Oct 2001
    Posts
    168

    Would you be willing to post the script?

    As jkeller said, this is a clever idea. Do you have a desire to post the script? I think a number of folks would find it useful, if not essential. I know I would!

    Thanks!

  6. #6
    Loyal Client
    Join Date
    Dec 2001
    Posts
    26

    php example I used

    I started with a HTML page (404.html) just to get the look n feel I wanted. Then I renamed it to 404.php and added a php section in the body (see generic example below). Of course, I had to change .htaccess to point to the 404.php.

    ----------------------
    <?php

    $ip = getenv ("REMOTE_ADDR");

    $requri = getenv ("REQUEST_URI");
    $servname = getenv ("SERVER_NAME");
    $combine = $ip . " hit the " . $servname . " 404 error page with path = " . $requri ;

    $httpref = getenv ("HTTP_REFERER");
    $httpagent = getenv ("HTTP_USER_AGENT");

    $message = " $combine \n
    HTTP_REFERER = $httpref \n
    HTTP_USER_AGENT = $httpagent
    ";


    $to = "[email protected]";
    $subject = "My 404 Notification";
    $from = "[email protected]";

    mail($to, $subject, $message,"From: $from\nX-Mailer: PHP/" .phpversion());
    ?>

    --------

    Hope this helps
    (BTW: I'm new to php so I had to use some extra variables ($combine, etc) so my simple mind could follow what was happening when I created my $message :weyes:

    John

  7. #7
    Loyal Client
    Join Date
    Oct 2001
    Posts
    168

    Thank you very much!

    Thanks from me! The visitors from my site will thank you also!

Bookmarks

Posting Permissions

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