0
$referer = null_change($_SERVER["HTTP_REFERER"], "");

When I execute the above, the following error is displayed.

Notice: Undefined index: HTTP_REFERER in (path) on line (number)

To solve that error, I created the following function and used it to assign default values of $_SERVER, $_POST, and $_GET.

function null_change(&$var, $type)
{
    if(is_null($var) === true) { $var = $type; }
}
$referer = null_change($_SERVER["HTTP_REFERER"], "");

This does not indicate any error, and now I can set default value to $_SERVER ["HTTP_REFERER"] with "".

However, some of posts below say that to use reference variables in PHP is dangerous.

https://stackoverflow.com/a/603488/8113216

https://schlueters.de/blog/archives/125-Do-not-use-PHP-references.html

I have read the above posts in detail, but I can't understand why using reference variables could be a problem in my case.

using reference variables can be a problem in my case?

update :

this question is about danger of reference variables. not about reliability of HTTP_REFERER.

Saturn
  • 55
  • 10
  • 1
    Your question is highly confused. I hammered it on the referrer part, but I realized the second link talks about *references* and not *referrers*. Neither is dangerous. The second link is 7 years old and some of what he says is no longer valid. References are useful as long as you understand them – Machavity Jun 29 '17 at 12:38
  • Sorry for the confusion. Now I see that reference variables(&$var) are not problem if I know how to use them. Thank you. @Machavity – Saturn Jun 29 '17 at 12:54

0 Answers0