How do I include IP address in notification email?

Dr. GBooky is here to help you with your guestbook problems ...
Post Reply
Jase
Posts: 5
Joined: Sun Feb 18, 2007 7:11 pm

How do I include IP address in notification email?

Post by Jase »

Have just upgraded to v1.5 mainly for the IP functionality due to consistent abuse of guestbook by one person. I delete malicious messages once they are posted but I need to try and keep a record of them hence I would like to include the IP address (and post time if possible) in the email notification.

What variable is used to store the IP address and can I reference it in the notification email? I have noticed $IP being used quite a lot but I have tried to include that in the email but it comes out blank - could I just use $REMOTE ADDR or is there a variable I can use already defined?

Also where can I change the date format to allow me to capture the time as well as date?

Many thanks

Jase
Jase
Posts: 5
Joined: Sun Feb 18, 2007 7:11 pm

Post by Jase »

Have been able to change the date format so its just the IP address in the notification email now please :)

Thanks
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

PHP Stores IP in the

Code: Select all

$_SERVER['REMOTE_ADDR']
variable.

If used inside quotes (like it the $message variable in GBook) you need to use it without the single quotes:

Code: Select all

$_SERVER[REMOTE_ADDR]


By the way, you can select IP to be banned when deleting a message or viewing IP from GBook.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Jase
Posts: 5
Joined: Sun Feb 18, 2007 7:11 pm

Post by Jase »

Klemen Stirn wrote:PHP Stores IP in the

Code: Select all

$_SERVER['REMOTE_ADDR']
variable.

If used inside quotes (like it the $message variable in GBook) you need to use it without the single quotes:

Code: Select all

$_SERVER[REMOTE_ADDR]


By the way, you can select IP to be banned when deleting a message or viewing IP from GBook.
Thanks Klemen - I had already used remote_addr but liked the way the GB script resolved the IP to a domaim which is why I wanted to use the variable already set but only because Im lazy!

Thanks for a great script :)

Jase
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

You can use PHP function gethostbyaddr() to get the resolving host (domain/ISP).
http://www.php.net/gethostbyaddr
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Me59
Posts: 49
Joined: Sun Sep 04, 2005 10:40 pm

Post by Me59 »

Ok, have done it and here the code for 1.5:

1) find line 739 reading:
$email=str_replace($repl,$char,$email);

2) add on line 740 (insert blank line):
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);


3) on line 747 add (under From:):
Sender: $hostname


thats all! - save the script, upload it and here ya go...
Post Reply