...

View Full Version : Getting an IP for a form



freerock1
10-23-2003, 08:00 PM
OK, I'm still a little new to PHP, but hopefully this is an easy one.

I know how to do a basic e-mail form, using the mail("[my address]", "[subject line]", $message, $mailheaders) tag. Basically right now I'm trying to do a web poll. I know I could just use a poll like mypoll.net, but I'd like to know how to do this on my own.

Is it possible to obtain the IP address of the voter, and if so, can I spoof the "From" and "Reply To" address as something like, somewebuser@IPaddress ?

Any help would be appreciated. Thanks

SDP2006
10-23-2003, 08:57 PM
Yes, there is a way, but I don't understand your question completely. For starters to echo the ip address
<?php
$theip = $_SERVER['REMOTE_ADDR'];
echo $theip;
?>

That will echo the users IP Adress....

freerock1
10-23-2003, 09:10 PM
Thanks for the reply. Basically, what I want to do is have the IP address come to me in the e-mail result that comes from the form. I don't want respondents to be required to enter their e-mail addresses, however.

In the form I'm using radio buttons; the value is "shows". I want the value name in the text of the e-mail. To add the IP to the text of the message, do I simply need to echo the IP, ie


<?php $theip = $_SERVER['REMOTE_ADDR'];

$message="$_POST[shows]\n$_POST[theip];

mail("mail@freerock1.com", "Shows Poll", $message);

?>
Also, since I don't necessarily need the sender's e-mail address, is it sufficient to just leave off the $mailheaders tags?

Thanks again.

Nightfire
10-23-2003, 09:17 PM
<?php

$theip = $_SERVER['REMOTE_ADDR'];

$message = $_POST['shows'] . "\n" . $theip;

mail("mail@freerock1.com", "Shows Poll", $message);

?>

freerock1
10-23-2003, 09:32 PM
Awesome. It works great.

Thanks so much; you've both been very helpful.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum