0

I have made this with my pages that are database generated with $_GET, but im starting to notice 404s from pages that are not database generated.

for example maybe incorrect directory name:

site.com/mispelleddir/page-name

or somehow the dir got printed twice:

site.com/dir/dir/page-name

I want to know that URL that was tried. Is there a way i can fetch the requested URL that gave a 404 into a php variable or something so i can include that in my error report? and or the page that it was linked to. I know i can see that sort of thing on google webmaster tools, but it takes them 2 days before they can report it to me. And usually in that time i could have fixed the problem already.

right now i have an email sent to me reporting it from the 404 page:

function report404($body)
{
    $to = "my email @gmail.com";    
    $subject = "website 404 error report";  
     if (!mail($to, $subject, $body)) 
    echo("<p>Message delivery failed...</p>");  
}

used like this on the 404 page:

if($_GET['page']) report404("The sentence [$page] was sent to eng.php or jap.php and could not generate a translation page.");
else report404("404 error occured but not from eng.php or jap.php");

when my database driven pages dont find the content in the db they redirect to 404 page setting the ?page="attempted page" but this wont work if the 404 error was trigger by those above examples.

user1397417
  • 708
  • 4
  • 11
  • 34
  • You could likely use an sql database, and copy the urls into that. Or you could use a mail program, and email the bad urls to yourself. – James G. Oct 16 '13 at 02:13
  • how do i retrieve the URL to send it in an email or to the db, thats what my question is – user1397417 Oct 16 '13 at 02:15
  • Check out this question: http://stackoverflow.com/questions/189113/how-do-i-get-current-page-full-url-in-php-on-a-windows-iis-server/ – James G. Oct 16 '13 at 02:17
  • and as for emailing it or putting it in the database, I use pear mail for email, and mysql for the database. I can't explain how those work to you in any short amount of time, but that gives you some stuff to google and research. – James G. Oct 16 '13 at 02:19
  • if i use $_SERVER["REQUEST_URI"] on the 404 page, this will just return the URL of my 404 page, which is site.com/404.php so how can i use it to do what i want? – user1397417 Oct 16 '13 at 02:23
  • no my bad, i tried it and it seems to be working. – user1397417 Oct 16 '13 at 02:31
  • Oh, I didn't think of that. But yeah, "request" is the requested url, as opposed to some of the other ones which would give the current url. – James G. Oct 16 '13 at 02:32
  • no no, it actually does give me the attempted url not the 404 page url.... So too bad i can't mark comments as correct answer... – user1397417 Oct 16 '13 at 02:37

1 Answers1

0

$_SERVER["REQUEST_URI"], as noted on (this question)[How do I get current page full URL in PHP on a Windows/IIS server, should work to get you the url.

You can then store that using pear email or sql.

James G.
  • 2,852
  • 3
  • 28
  • 52