Page 1 of 2

What page sent 'em to 404.php?

Posted: Sat Dec 13, 2003 11:30 am
by vinyl-junkie
I've searched LOTS of places, including here, and haven't found what I'm looking for. The saga continues of my conversion from ASP to PHP, with this question. On my custom 404 page in ASP, I have something like "the page you were trying to access - http://www.somepage.com - was not found or is no longer here." and so forth. In PHP, how do I do the same thing - capture what sent them to my 404 page? HTTP_REFERER doesn't work for that purpose, so what does?

Posted: Sat Dec 13, 2003 3:07 pm
by m3mn0n
REQUEST_URI or PHP_SELF

Posted: Sat Dec 13, 2003 3:32 pm
by DuFF
you can use either of those in the $_SERVER global.

Example:

Code: Select all

$_SERVERї'PHP_SELF']
$_SERVERї'REQUEST_URI']

Posted: Sat Dec 13, 2003 4:00 pm
by vinyl-junkie
Thanks for the suggestions, but none of them worked. All those server variables return the name of the 404 page. :(

Posted: Sat Dec 13, 2003 4:14 pm
by volka
how did you register you custom 404 page?

Posted: Sat Dec 13, 2003 5:01 pm
by vigge89
Create a file with the following content:

ErrorDocument 404 /404.php

Name it as .htaccess

Posted: Sat Dec 13, 2003 5:13 pm
by volka
I didn't want to know how it is possible but how it has been done.
But thx ;)

Posted: Sat Dec 13, 2003 5:57 pm
by vinyl-junkie
vigge89 wrote:Create a file with the following content:

ErrorDocument 404 /404.php

Name it as .htaccess
At the risk of being picky, doing a .htaccess file only works on a Unix system. If you have a website that's on a Windows server, you can still have a custom 404 error page, but your web host will probably have to set that up for you.

Posted: Sat Dec 13, 2003 6:13 pm
by volka
no, apache/win32 can do just the same.
But how did you do it?

Posted: Sat Dec 13, 2003 6:20 pm
by qads
sorry if i am hijacking this post but i also tried useing

Code: Select all

ErrorDocument 404 /404.php
but it didt work at all, i am runing XP with Apache/1.3.27 (Win32) PHP/4.3.3RC1 :?. so maybe the above code doest work? 8O

Posted: Sat Dec 13, 2003 6:24 pm
by vinyl-junkie
qads wrote:sorry if i am hijacking this post but i also tried useing

Code: Select all

ErrorDocument 404 /404.php
but it didt work at all, i am runing XP with Apache/1.3.27 (Win32) PHP/4.3.3RC1 :?. so maybe the above code doest work? 8O
No problem with the hijacking. This is an important topic after all. :D

The above code should work, provided you have your 404 page named 404.php, and it is in your root directory.

Posted: Sat Dec 13, 2003 6:37 pm
by qads
nope, just tried it agian, no go :?

Posted: Sat Dec 13, 2003 6:44 pm
by volka
and again...
vinyl-junkie: How and where did you set up your 404.php page?
with ErrorDocument in your httpd.conf?
is php installed as module or as cgi?

Both, $_SERVER['REDIRECT_URL'] and $_SERVER['REQUEST_URI'], should give you the actually requested url.

Posted: Sat Dec 13, 2003 9:35 pm
by vinyl-junkie
volka wrote:and again...
vinyl-junkie: How and where did you set up your 404.php page?
404.php is a web page, just like any other on your website. Just set it up with whatever message you want and visitors will get automatically redirected to it if you have a page that moved, they hand-type an incorrect URL, or whatever. Go here to see how mine looks on my Windows hosted site:
http://www.napathon.net/xx.asp
Notice the part that shows you how you ended up there. Somehow, there's gotta be a way of doing the same thing in PHP.
Both, $_SERVER['REDIRECT_URL'] and $_SERVER['REQUEST_URI'], should give you the actually requested url.
Still no joy. One of these didn't return any value at all. The other still returned /404.php as the URL. *sigh*

Posted: Sat Dec 13, 2003 11:38 pm
by m3mn0n
Oops. Sorry for misreading your inquery. ;)

Check out: http://httpd.apache.org/docs-2.0/custom-error.html

It might have some details that can help you.
Apache will define REDIRECT_URL and REDIRECT_STATUS to help the script trace its origin. Both the original URL and the URL being redirected to can be logged in the access log.