2

I have develop a simple modal box and I added $_SERVER["HTTP_REFERER"] so from specific referrer to do not appear. It works fine but the $_SERVER["HTTP_REFERER"] is not working on Mozilla. Is there any other way to do this?

I am using the simple PHP code:

if ($_SERVER["HTTP_REFERER"] == "www.thedomain.com/article.php"){
//Code to do not show the modal box
}else{
//code to show the modal box
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Irene T.
  • 1,393
  • 2
  • 20
  • 40
  • 4
    The referer would include the protocol `http://` Do a `var_dump($_SERVER['HTTP_REFERER'])` to see what it actually contains. – Michael Berkowski Dec 20 '14 at 15:33
  • 4
    However, it is entirely up to the client browser to send or not send or mangle the HTTP_REFERER string, or send whatever the heck it wants to or the user configures it to. It may not be present at all, and is generally pretty unreliable. – Michael Berkowski Dec 20 '14 at 15:34
  • Try `print_r($_SERVER);` to see what variables you have access to. It won't be browser-dependent - if Firefox cannot see it in a particular case, neither can the others. – halfer Dec 20 '14 at 15:40
  • i did a var_dump($_SERVER['HTTP_REFERER']) and on firefox i am gettin nulled! – Irene T. Dec 20 '14 at 21:57

2 Answers2

1

'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.

http://php.net/manual/en/reserved.variables.server.php

In other words, you should not be relying on this value in your code. That said there is not really a better reliable way to get this information. You simply do not always have access to this information from the user's browser.

Casey Rule
  • 2,085
  • 2
  • 18
  • 28
1

As explained, you can't rely on the referrer. Some users choose to disable the referrer altogether, and over HTTPS it's always blank.

Just use a query string parameter, like &modal=true.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272