parse_url($HTTP_REFERER) not returning any values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rsraloha
Forum Newbie
Posts: 4
Joined: Thu Jul 06, 2006 10:06 am

parse_url($HTTP_REFERER) not returning any values

Post 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
Last edited by rsraloha on Thu Jul 06, 2006 12:36 pm, edited 1 time in total.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
rsraloha
Forum Newbie
Posts: 4
Joined: Thu Jul 06, 2006 10:06 am

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
rsraloha
Forum Newbie
Posts: 4
Joined: Thu Jul 06, 2006 10:06 am

Post 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.
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Post 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.
rsraloha
Forum Newbie
Posts: 4
Joined: Thu Jul 06, 2006 10:06 am

Post by rsraloha »

thanks for all the help, issue has been resolved
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

FYI:

$_SERVER['PHP_SELF'] is vulnerable to injection attacks.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
Post Reply