GeekInAsia Posted July 2, 2010 Share Posted July 2, 2010 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); } } ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 2, 2010 Share Posted July 2, 2010 You'll likely want to set up a database table to store the ip addresses and a timestamp in, then only insert the address if it doesn't already exist in the table (or update the timestamp if it does). You could also use the timestamp so the mail script would be able to run every xx minutes or hours on a cron job and send any new entries rather than a separate mail for each one. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.