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 = "[email protected]"; $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 = "[email protected]"; $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); } } ?> Link to comment https://forums.phpfreaks.com/topic/206481-function-to-alert-me-when-someone-outside-our-ip-address-accesses-a-page/ 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. Link to comment https://forums.phpfreaks.com/topic/206481-function-to-alert-me-when-someone-outside-our-ip-address-accesses-a-page/#findComment-1080100 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.