Jump to content

firefox vs ie7 & any other browsers problem with HTTP_REFERER


rj2kix

Recommended Posts

hello,

 

i have a simple code for my website, that checks to see if they were sent to the page thru the appropriate referral page.  if not, they are then redirected to the home page and denied access to said page.

 

this code i have works fine on firefox, but just today i discovered it does not work on ie7 and who knows what other browsers it might not work on. 

 

if you could please review and then give some advice i'd really appreciate figuring out this problem.

 

<?

$ref = getenv("HTTP_REFERER");

$pos = strpos($ref,"results1.php");

if ($pos === false) {

$URL="http://www.truelifekarma.com/index.php?aff=resultspage";

header ("Location: $URL");

} else {

}

?>

Link to comment
Share on other sites

Try using phpinfo() to see exactly what IS set by IE 7.  Then you can go from there.

 

I disagree - HTTP_REFERRER should really only be used for data collection purposes - not security. As thorpe said, it is unreliable at best. For instance, whilst firefox does send the referrer by default, it can be set up not to. I think you'll find that there are some firewalls which block the sending of the referrer too.

 

well i use this script to protect my results end pages from users who just go straight to them without going thru my site first.

 

is there any other methods i can employ that is mutli browser compatible?

 

As for that, you could set a session on the page you want people to go through first - and on the results page, check this session exists. If it does not, you can redirect them to the home page - if it does, then let them view the results.

Link to comment
Share on other sites

HTTP_REFERER is an excellent method of detecting and denying access to unauthorized links to your files.

 

It is an insufficient method of preventing direct downloads by a determined user.  It does not prevent this.

 

If all the OP wants is to prevent direct links to his files from other sites, then HTTP_REFERER is not only appropriate but is ideal.  All the arguments against HTTP_REFERER make the assumption that the user using the browser is malicious, but it still provides protection against a malicious website.

Link to comment
Share on other sites

okay so i implemented sessions, good idea.

 

had session start on the page where they finish taking the Karma Test and set a session variable.

 

Then on the Results page that they are supposed to only see if they've taken the test, I check to see if that sesion variable is set, if it is not set, they go back to the home page.

 

WELLLLL This AGAIN works perfectly in Firefox but STILL does not work in IE7!!!

 

I am getting very frustrated.

Link to comment
Share on other sites

never replie on HTTP_REFERER, personally i try to use it as little as possible..

 

'HTTP_REFERER'

    The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

Link to comment
Share on other sites

rj, what did phpinfo() show differently for firefox and IE7?

 

If sessions do not work with IE7, that indicates that IE is configured not to accept cookies, or not to pass cookies to the pages you want to pass them too.  Does a simple session example with a single file work with IE7?

 

Regarding criticisms of HTTP_REFERER, it is perfectly ok to use it as long as you understand its limitations.  Websites should always be designed for the majority of users, and the majority will send HTTP_REFERER correctly with each request.

Link to comment
Share on other sites

Sessions shouldn't have any issues with a single browser, yes you can delete session data, but you can't adjust it on your own since its server side. 

 

As for the http_refer, it was one of those legacy things that use to be a very common part of the language construct, but with time its reliable has wavered and thus is is part of the language construct for legacy purposes.  I believe there is a revamping of the Superglobals completely in six that might even include a removal of this, but I am unaware of the specifics, all I know is that registered globals is no longer an option, defaulted to OFF :)  Yes it does contain some data who's reliability is none at best, but on a large scale, such as a website with 100k+ hits a day, tracking the in routes with it will yield semi accurate results (Depending on your confidence interval).  However on a smaller scale when the distribution of browsers is not equal to the norms, odds of it having any reliability dramatically drop.

In a nutshell the only time you would use this superglobal would be to track navigation around your site, but at best it can only be used as an estimation.

Link to comment
Share on other sites

HTTP_REFERER is nothing to do with globals.  It's a variable sent by the browser to the server, and ALL such variables must be made available to the php script in one form or another.  Anything else is insanity.  Currently the recommended method of access is $_SERVER

 

register_globals and superglobals is another issue altogether, and has nothing to do with availability or accuracy of HTTP_REFERER.

 

As for its accuracy, it remains high, unless your userbase is skewed towards technically inclined users.  I can't believe that some people claim that it is unreliable when all real evidence is clearly to the contrary.

 

FYI, my work involves clickstream processing of something like 200 million hits daily, where most of our data sources include the HTTP_REFERER data.

Link to comment
Share on other sites

It is not a reliable enough system to use for a single purpose of a 1/0 test.  It is reliable enough for large level data collection, but beyond this its uses are limited.  Yes as I stated it as a positive exponential correlation between accruals and number of trials, but in terms of say if($_SERVER['HTTP_REFER']) == "Formpage.php"){//process}

This is just to unreliable to be a realistic solution.

Link to comment
Share on other sites

... but in terms of say if($_SERVER['HTTP_REFER']) == "Formpage.php"){//process}

This is just to unreliable to be a realistic solution.

 

But it IS reliable enough to be a realistic solution.  It works perfectly fine in practice.  Read my earlier post in this thread for details on when it works and when it doesn't.

Link to comment
Share on other sites

IE7 Blocks it, (see IE7 Security/privacy settings)

Your need to use something new.. cookies,sessions, GET etc

 

 

never replie on HTTP_REFERER, personally i try to use it as little as possible..

 

'HTTP_REFERER'

    The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

Link to comment
Share on other sites

what can i use in place of HTTP_REFERER ?

 

because I also use it for detecting where my incoming links are to correlate them with potential conversions for my admin stats.

 

 $ref = $_SERVER['HTTP_REFERER'];  

    
  if (strpos($ref,"myspace.com") !== false && strpos($ref,"myspace.com") != '')  
       setcookie("aff", "myspace");  
  elseif (strpos($ref,"google.com") !== false && strpos($ref,"google.com") != '')  
       setcookie("aff", "google");  
  elseif (strpos($ref,"yahoo.com") !== false && strpos($ref,"yahoo.com") != '')  
       setcookie("aff", "yahoo");  
  elseif (strpos($ref,"msn.com") !== false && strpos($ref,"msn.com") != '')  
       setcookie("aff", "msn");  
  else  
       setcookie("aff", "typein");  
    
  }  
    

Link to comment
Share on other sites

If you are using http_referer for data collection purposes, which is not crictical to the running of your site, then that is fine.

 

However, i would disagree with btherl that only technically minded people may be making requests without an http referer being sent. As i've said before, some filewalls (notably norton filewalls - google and you'll see) by default disable the sending of the http referer. This is the main reason why i feel that using the http referer to prevent access is a bad idea - perfectly legitimate computer illiterate users can be blocked. However, i will agree that it can be used to prevent other sites linking to your files - if the http referer is present and it is not from your website and the file being retrieved should only be accessed from a user already on your website, then it is a method of protection against the non technically minded.

 

Sessions shouldn't have any issues with a single browser, yes you can delete session data, but you can't adjust it on your own since its server side. 

 

Incorrect. Unless you set PHP up to pass the session id around in the URL, cookies need to be enabled for sessions to work.

 

As for the question rj2kix: im not sure what you're really trying to do? Why would you store the name of the website that a user came from in a cookie?

Link to comment
Share on other sites

on my index page i store the referrer of the website in a cookie, and on my signup page, it checks to see if the cookie was set by a common referrer, or by an affiliate.

 

this will then update my admin statistics with who is referrering me the most signups.  whether it be search engines, myspace, affiliates, etc.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.