Forum Moderators: coopster

Message Too Old, No Replies

Email Notification

When a certain IP is detected

         

wfernley

3:09 pm on Aug 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

I was curious how I can get my website to email me when a IP is detected on my site.

I know I would have to get the users $_SERVER['REMOTE_ADDR'] and then run it with the ip I am looking for. The problem is the ip I am looking for is a subnet. So I cant specifically look for 123.45.67.890, but I need to look for 123.45.67.*. How can I do this?

The actual email part is fine I have that setup I guess its just the ripping apart of the $_SERVER['REMOTE_ADDR'] to see if the beginning matches the ip I am looking for.

Does anyone know how I can do this?

Thanks :)

wes

mattx17

4:54 pm on Aug 3, 2005 (gmt 0)

10+ Year Member



Use a quick regular expression to match it. You may also want to set a cookie on the remote browser so you don't end up getting a multiple e-mails per visit.

if (preg_match("#123\.45\.67\.[0-9]{1,3}#",$_SERVER['REMOTE_ADDR']) &&!$_COOKIE['MailSent']) {
mail('you@example.com','IP Detected',$_SERVER['REMOTE_ADDR'] . ' Detected!');
setcookie('MailSent','TRUE');
}

wfernley

5:15 pm on Aug 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Great thanks mattx17!

That worked perfectly.