Forum Moderators: coopster

Message Too Old, No Replies

how to find out what page the user wanted to be at?

php function to return requested filename/URL

         

matun

4:54 pm on Apr 16, 2007 (gmt 0)

10+ Year Member



Hi folks,

I've done some custom 404 error messages, and this works fine, but I want to add some extra functionality to my script, too.

So, I implemented "the perfect 404" by A List Apart dot com and it works just fine, but this approach gives only the backlink where the 404 error page was triggered from by the presceding URL, so my mails I am getting from the script gives only the root link and not the link I want to know that was not correct.

So I am looking in what way I could pass some variable which contains the base url the user clicked on but since it does not exist the 404 page was triggered.

I was thinking on basename(), but am not sure is this the right way of doing it?

Err, it seems even to me that I wrote a bunch of nonsence, so I'll try this way:

My user type my base URL, www.something.com. The index.php page loads, and it contains a few linkd (link1.php, link2.php, link3.php). The links 1 and 2 exist and work fine, but if my user click on link3.php, a 404 error message comes in, and it says to user that the page link3.php does not exist and ask her kindly that she report this problem to the webmaster. Than (if she chooses to report the problem) a mail notification submits to my mailbox saying something like this:
Subject: "A problem occured at your website!"
Body: This problem came from: http://www.example.com/index.php
Link in question: http://www.example.com/404.php
Date reported: April 16th, 2007 Mon, 16 Apr 2007 18:17:20 +0200

Anyone?

[edited by: jatar_k at 4:59 pm (utc) on April 16, 2007]
[edit reason] please use example.com [/edit]

cameraman

5:12 pm on Apr 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The name of the missing page is in $_SERVER['REDIRECT_URL'].
I have mine set up so that if the REFERER is my own site it emails me automatically - doesn't ask first.

matun

6:50 am on Apr 17, 2007 (gmt 0)

10+ Year Member



Could you post your code here or send me a private message with your code maybe?

Tnx for your help

cameraman

10:25 am on Apr 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mine does several things, but the mail part isn't very complicated. I use a class called htmlmimemail (you can find it with your favorite search engine) that does the mailing, so it's just a matter of setting the variables.

if(strpos($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST'])!== false) {
require_once "htmlMimeMail-2.5.2/htmlMimeMail.php";
$message = <<<EOT
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Not found:<br>
{PAGE}</p>
<p>Referring page:<br>
{REFERER}</p>
</body>
</html>
EOT;

$message = str_replace('{REFERER}',$_SERVER['HTTP_REFERER'],$message);
$message = str_replace('{PAGE}',$_SERVER['REDIRECT_URL'],$message);

$emailer = new htmlMimeMail();
$emailer->setSMTPParams(null,null,null,true,$username,$userpass);
$emailer->setHtml($message);
$emailer->setFrom('webmaster@example.com');
$emailer->setHeader("Date",substr(gmdate("r",time()-25200),0,-5) . "-0700");
$emailer->setHeader("ReplyTo",'webmaster@example.com');
$emailer->setSubject('Error 404 at the site');
$emailer->setReturnPath('webmaster@example.com');
$result = $emailer->send(array('webmaster@example.com'),'smtp');
} // EndIf bad link from here

jatar_k

12:49 pm on Apr 17, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



another thing you can do is dump the whole $_SERVER var to see what you have available when the 404 page is called

echo '<pre>';
print_r($_SERVER);
echo '</pre>';