Mohammad Alipour Mohammad Alipour - 4 months ago 19
PHP Question

What is the difference between $_SERVER['HTTP_REFERER'] and $HTTP_REFERER?

I'm looking in an old script.
I found a code :

ereg($self_name, $HTTP_REFERER)


Can I change that code to the following code?:

if(isset($_SERVER['HTTP_REFERER']))


or change it to

preg_match("%$self_name%", $HTTP_REFERER)


What is the difference between
$HTTP_REFERER
and
$_SERVER['HTTP_REFERER']
?

note:

//Site name for security checks:
$self_name = '.*';

Answer

ereg and $HTTP_REFERER are both deprecated and shouldn't be used anymore. use

preg_match("%$self_name%", $_SERVER['HTTP_REFERER'])`

Note that :

if(isset($_SERVER['HTTP_REFERER']))

only checks if refere is set or not But

preg_match("%$self_name%", $HTTP_REFERER)

check that refere is in $self_name or not