Forum Moderators: coopster

Message Too Old, No Replies

404 redirection

Dynamic page generation

         

rezash

7:33 am on Jan 14, 2005 (gmt 0)

10+ Year Member



All not found files on my site redircts to my 404.php file.
Inside my 404.php file i'd like to find out the original not found url and extract the file name.

for example if someone clicks on www.mysite.com/123.php or www.mysite.com/78.php I would like to extract 123 or 78 strings. How?
I tried both $_SERVER['PHP_SELF'] and $_SERVER['HTTP_REFERER'] but Apache does not sent the original not found URl to my 404.php page.

Any code/help would be appricated.

I would like to be able to setup my custome 404.php file and after extracting the number in url display dynamic pages.
Thanks for reading and any feedback
-Reza

tomda

7:58 am on Jan 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is strange that you can not get the $_SERVER variables. Normally, you should be able to get them?

Anyway, this is the function I use in my 404 page. It just send you an email with the following information :


function send_error_email( $error_code='Undefined' )
{ $to = '#*$!@xxxx.xx';
$subject = "An error at xxxxx - type: $error_code";
$message = "The following error has occured:\r\n"
."--------------------------------\r\n\r\n"
." Type: $error_code\r\n"
." Page: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}\r\n"
." From page : {$_SERVER['HTTP_REFERER']}\r\n"
." Time: ".date('d/m/Y H:i:s')."\r\n"
." From IP: {$_SERVER['REMOTE_ADDR']}\r\n\r\n"
."Regards,\r\n";

email($to, $subject, $message);}

Do not forget to add this line in the 404page to call the function.
send_error_email("404");

Give it a try and let us know.

rezash

5:50 am on Jan 15, 2005 (gmt 0)

10+ Year Member



You're right getenv("REQUEST_URI") works and I was able to extract script name.
Thanks for the code,
-Reza