user220755 user220755 - 4 months ago 10
PHP Question

Referral URL in php

So I am trying to get the page where a visitor came from. I inserted this code into a php file and I am trying to see the page's URL but it is not working, any suggestions?

<?php

$ref = getenv("HTTP_REFERER");
echo $ref;

?>


(added this after some answers)
I have also tried

print $_SERVER["HTTP_REFERER"];


and that doesn't work either

it worked after i updated the website many times, not sure why was there a problem in the first place, thanks anyway :)

Answer

Have you tried accessing through the $_SERVER superglobal?

print $_SERVER["HTTP_REFERER"];