Ok, so I'm trying to do a simple action where if a user was already viewing our site, we'll display a certain message, otherwise, we want to show a message for first time visitors (or just those without our URL as their referrer)
Else statement only shows as blank regardless how I seem to spin this.
Ideas?
<?php
if (isset($_SERVER['HTTP_REFERER'])) {
$referer = $_SERVER['HTTP_REFERER'];
if (strpos($referer, "http://www.example.com/") === 0) {
echo "Match Okay";
} else {
echo "No Match";
}
}
?>
Your code seem ok.
Quoted from the php docs:
Maybe your browser belongs to the category "Not all user agents will set this". Try your code with another browser.
For a more reliable way do to that, consider using cookies! Simply check for a cookie value. If it is not present, it's a first time visit (then set the value). If it is present, then it's at least the second page loaded.
The advantage of cookies is that you can track user if they come back again (by setting a persistence time for the cookie)