View Full Version : getting less info than REFERER is giving me

10-16-2003, 12:46 AM
I'm thinking about something I could do if I could know the previous page the user is coming from (always inside my site). When I use $_SERVER['HTTP_REFERER'], the var is giving me for example: http://www.mysite.com/files/thispage.php?m=12&set=true but what I really need is only: thispage.php. Is there any other predefined var to get that or should I use a preg_replace or so?

10-16-2003, 09:01 AM
i would say you shlould go with preg_replace, and it shouldnt be too difficult either unless ur pages have names with ? in them... but i cant remember if thats allowed or not:rolleyes:

10-16-2003, 01:50 PM
With parse_url() and basename() you can do that:

$urlParts = parse_url($_SERVER['HTTP_REFERER']);
$file = basename($urlParts['path']);
print $file;

10-16-2003, 03:11 PM
Thanks guys, the second option is what I need, but I'll be carefull 'cause I've read (http://www.php.net/manual/en/reserved.variables.php) HTTP_REFERER does not always work as expected. :thumbsup: