Page 1 of 1

parse_url($HTTP_REFERER) not returning any values

Posted: Thu Jul 06, 2006 10:18 am
by rsraloha
parse_url($HTTP_REFERER)
I cannot seem to get this function call to return an array of values(returns nothing) ON my localhost.

I have done some research and came across some different ideas as to why its not returning

1. My Firewall is stripping this info
2. Apache is not configured properly
3. php is not configured properly

I am running php4.1.3 and apache2 on XP

Can anyone help, this thing has killed hours of productivity

Thanks in advance

Posted: Thu Jul 06, 2006 10:24 am
by Jenk
have you tried

Code: Select all

$vars = parse_url($_SERVER['HTTP_REFERER']);
instead?

btw - don't forget HTTP_REFERER doesn't always have a value and is infact, unreliable.

Posted: Thu Jul 06, 2006 10:28 am
by rsraloha
Ya I am assigning

$url = parse_url($_SERVER['HTTP_REFERER']);

I know it is unreliable but I have taken over an application that uses it
and I am trying to simpy get the application running before I go tweaking anything

BTW this code is returning and functional in production, it will
not work on my local environment.

thanks

Posted: Thu Jul 06, 2006 10:41 am
by RobertGonzalez
HTTP_REFERER is not a reliable server variable. Some servers set it, others do not. HTTP_X_FORWARDED_FOR is just as unreliable. Is there another way to get at what you are looking for other than using server vars?

Posted: Thu Jul 06, 2006 10:58 am
by rsraloha
I am sure there is a better solution than using this server variable

But,
I am working with an app that is live in production and am trying to get
the stable version from the production server running on my machine without modifying any code

how can I configure my server to return this info

LocalHost is Apache2.0 and
Production Server is the same

Is this an apache config issue.

Posted: Fri Jul 07, 2006 5:14 am
by mattcooper
Have you tried something like this?

Code: Select all

echo "<a href = ". $_SERVER['PHP_SELF'] .">Click me</a>";
echo "<p>referer:". $_SERVER['HTTP_REFERER'] ."</p>"; // confirms there is no prob with server settings; once you've clicked, you get the referer

$url = parse_url($_SERVER['HTTP_REFERER']);
echo "URL: - ".$url['scheme'];$url['host'];$url['path']; // This should echo out the referrer from $url
You'll get output when you click the link. You should be able to see the referer from the components of the $url array.

Hope this helps.

Posted: Fri Jul 07, 2006 8:24 am
by rsraloha
thanks for all the help, issue has been resolved

Posted: Fri Jul 07, 2006 8:53 am
by Jenk
FYI:

$_SERVER['PHP_SELF'] is vulnerable to injection attacks.

Posted: Fri Jul 07, 2006 8:57 am
by Ambush Commander
Anything of this manner will really be makeshift. You could try __FILE__, but it's difficult to do with directory structures.

My recommendation is that when you have the resources and ability to do so, define a clear format for representing pages and then pass that to the page that will bounce the client back to the previous page.