I am trying to create a simple function that I can call from the start of each page. It is simply checking where a users is in the UK or trying to access whilst overseas. I have the detection working fine, however it alerts me every time they reload or change a page. What i want is just to be alerted once. My code it below if someone can point out my mistakes I would appreciate it.
<?php
if (getenv(@HTTP_X_FORWARDED_FOR))
{
$tmp_SurferIP = @getenv(HTTP_X_FORWARDED_FOR);
} else {
$tmp_SurferIP = @getenv(REMOTE_ADDR);
}
$tmp_SurferCountry = geoip_country_code_by_addr($gi, $tmp_SurferIP);
if ($tmp_SurferCountry != "GB")
{
if (@$_SESSION['SurferCountryDenied'] != TRUE)
{
$tmp_SentToEmail = "ehostmanager@gmail.com";
$tmp_MessageSubject = "Site Access Denied Notice - ".$tmp_SurferCountry." - ".$tmp_SurferIP;
SendEmail ($tmp_SentToEmail,$tmp_MessageSubject,$tmp_MessageBody);
@$_SESSION['SurferCountryDenied'] = TRUE;
}
echo "Sorry you are not in the UK, so access to this site has been denied";
exit;
}
else
{
if (@$_SESSION['SurferCountryGranted'] != TRUE)
{
$tmp_SentToEmail = "ehostmanager@gmail.com";
$tmp_MessageSubject = "Site Access Granted Notice - ".$tmp_SurferCountry." - ".$tmp_SurferIP;
$tmp_MessageBody = "The IP address <strong>".$tmp_SurferIP."</strong> has been granted access to the site due to being detected within the United Kingdom";
@$_SESSION['SurferCountryGranted'] = TRUE;
SendEmail ($tmp_SentToEmail,$tmp_MessageSubject,$tmp_MessageBody);
}
}
?>