Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, I'm somewhat new to the whole web design thing and was wondering if there was any way to put some code or a script into a web page that, when someone with the IP Address xx.xx.xx.xx hits that particular page, the code or script would automatically send an email at the time of the hit?
Is this possible? Can anyone post the code?
Thanks in advance.

With php, you could possibly try the mail function
<?php if(strcmp($_SERVER["REMOTE_ADDR"], "127.0.0.1") == 0) { $name = "sender's name"; $from = "from@host"; $sendto = "to@host"; $body = "the page got a hit from:\r\n" . $_SERVER["REMOTE_ADDR"] . "\r\n" . gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\r\n" . $_SERVER["HTTP_USER_AGENT"] . "\r\n" . date('M d, Y h:i a', time()) . "\r\n"; $subject = "hit from target site"; $header = "From: ". $name . " <" . $from . ">\r\n"; mail($sendto, $subject, $body, $header); } ?> rest of script
The second parameter in strcmp should be that of the ip you're looking for. I have no ideas on other scripting languages.HTH

It took me a while to figure out how to use php. I'm still quite foggy on it all, BUT the important thing is, after much trial and error trying to figure out how to apply your script, I did it! Thank you SOOOO much for your help in this. It was driving me crazy, and I finally figured out where to put what. Again, thank you for your help.

I hate to ask for more, but I'm really excited that it's working. How would I input variables for more than one IP Address? For instance, I have it set to alert me when a specific IP address hits my page, but I'd also like to find out when an IP Address that starts out as (for instance) "32.143.xx.xx" hits my page. What are the variables or wildcards for the other digits in the IP Address that would allow me to do that?
Again, thank you so much for your help. I'm still learning (teaching myself through googling and trial and error) so please for give my thickness to what may be a very simple answer.

<?php define("ADD1", 32); define("ADD2", 143); $ip = array("34.212.22.110", "32.212.100.143", "32.143.112.2", "65.23.111.233", "32.143.20.96", "113.32.143.11", "119.156.32.143"); foreach($ip as $val) { $pat = '/(' . ADD1 . '\.' . ADD2 . ')\.([[:alnum:]]+)\.([[:alnum:]]+)/'; echo $val . (preg_match($pat, $val) > 0 ? " <strong>true</strong>" : " false") . " "; } ?>
I *think* something like above will work; I made an array to test ips, but you wouldn't need the foreach loop or the array.replace
if(strcmp($_SERVER["REMOTE_ADDR"], "127.0.0.1") == 0) {
withif(preg_match($pat, $_SERVER["REMOTE_ADDR"]) > 0) { // add mail routine here }I used define to "fix" part of the ip, but you can use variables too.
HTH

![]() |
upload images from webpag...
|
Microsoft Certificate Ser...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |