Scenario: I want to detect from which website my visitors are coming from an javacript SRC.
Visitor from google.com ----> My Website(Detect if visitor come from google)
<script type="text/javascript" src="ref.php"></script>
refer.php
<?php
if (strstr($_SERVER['HTTP_REFERER'], 'google.com') !== false) {
header("Location: http://mywebsite.com/organic-traffic.js");
}
else {
header("Location: http://mywebsite.com/frequent-visitors.js");
}
?>
The above PHP code doesn't work. But if I use normal javascript "document.referrer" its detected.
If I access the file ref.php directly then the refer is detected also. Looks like its taking My website as referral and not google.com