0
votes

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.

1
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 Gould
how do i retrieve the URL to send it in an email or to the db, thats what my question is - user1397417
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 Gould
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

1 Answers

0
votes

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