/    Sign up×
Community /Pin to ProfileBookmark

Is there a way to collect someone’s IP address when they submit a form, then display that IP address in your e-mail that you get from that form… I am just asking because people have been using some unnesessary language in forms that are meant for good means… This way I can bann the user that has violated such viciousness.

to post a comment
PHP

15 Comments(s)

Copy linkTweet thisAlerts:
@brendandonhueJul 11.2003 — If you are using Pyro's email script to process the form, just add this to your form.

<input type="hidden" value="<?php echo $_SERVER['REMOTE_ADDR']?>">

If someone really wanted to, they could edit the source of your page and remove that line, then use the form, but I doubt they will do that. If they do , post back and I'll give you a line to add to the script itself.
Copy linkTweet thisAlerts:
@JonathanauthorJul 11.2003 — what is the one where they can't use it
Copy linkTweet thisAlerts:
@brendandonhueJul 11.2003 — <?PHP

$subject = "Feedback";

$headers = "From: Form Mailer";

$forward = 1;

$location = "feedbackthankyou.html";

$addresses = array("[email protected]","[email protected]","[email protected]");

$date = date ("l, F jS, Y");

$time = date ("h:i A");

$IP = $_SERVER['REMOTE_ADDR'];

$msg = "This form was submitted on $date at $time.nn";

$msg = $IP . $msg

foreach ($_
POST as $key => $value) {

$msg .= ucfirst ($key) ." : ". $value . "n";

}

foreach ($addresses as $email) {

mail($email, $subject, $msg, $headers);

}

if ($forward == 1) {

header ("Location:$location");

}

else {

echo ("Thank you for submitting our form.");

}

?>
Copy linkTweet thisAlerts:
@JonathanauthorJul 11.2003 — Sorry, had to eat lunch... thanks for the script
Copy linkTweet thisAlerts:
@brendandonhueJul 11.2003 — No prob
Copy linkTweet thisAlerts:
@ExtremeJul 13.2003 — Why won't this work for me..

[code=php]
<?
$IP = $_SERVER['REMOTE_ADDR'];
mail("[email protected]","Subject..", "IP: $IPn");
?>
[/code]


I even tryed adding this

<input type="hidden" value="<?php echo $_SERVER['REMOTE_ADDR']?>">

to my from, but nothing.... I get email and all but no IP.. It's just empty after "IP:" text...
Copy linkTweet thisAlerts:
@pierskJul 17.2003 — I copied and pasted exactly the code that you entered below, and it gave me the correct IP address. Maybe your server isn't configged correctly or you are behind some proxy server ?(plucking at straws here...)
Copy linkTweet thisAlerts:
@JonathanauthorJul 17.2003 — I am registered w/ www.globat.com

And, I got the e-mail when I didn't have the IP address... so what is happening?
Copy linkTweet thisAlerts:
@pyroJul 17.2003 — You could try this:

[code=php]<?
$IP = $_SERVER['REMOTE_ADDR'];
mail("[email protected]","Subject..", "IP: ".$IP."n");
?>[/code]
Copy linkTweet thisAlerts:
@Da_WarriahJul 17.2003 — also, if you/your server is running less than PHP 4.1.0 (servers usually tell you what version they run), superglobals wont work...

try $HTTP_SERVER_VARS['REMOTE_ADDR'] instead of $_SERVER['REMOTE_ADDR'] and see if that makes a difference...and check [URL=http://www.php.net/manual/en/language.variables.predefined.php]here[/URL] for more details...?
Copy linkTweet thisAlerts:
@ExtremeJul 18.2003 — Yeah, it works this way....Thanks everyone...
Copy linkTweet thisAlerts:
@pyroJul 18.2003 — Which way?
Copy linkTweet thisAlerts:
@ExtremeJul 18.2003 — This:

try $HTTP_SERVER_VARS['REMOTE_ADDR'] instead of $_SERVER['REMOTE_ADDR'][/QUOTE]

I guess my webserver was an error... Can someone check this out and see if any of this can be updated so I can work with PHP without a problem.... This is what they have now...
Apache/1.3.19 (Unix) (Red-Hat/Linux) mod_ssl/2.8.1 OpenSSL/0.9.6 DAV/1.0.2 PHP/4.0.4pl1 mod_perl/1.24_01[/QUOTE]
Copy linkTweet thisAlerts:
@Da_WarriahJul 19.2003 — well its just that your server has a slightly out-of-date version of PHP - 4.[b]0[/b].4 instead of 4.1.0, which is when they introduced the $_SERVER variables...

by just using $HTTP_SERVER_VARS, it will achieve the same effect, only slightly more of a strain on the fingers, thats all?
Copy linkTweet thisAlerts:
@pyroJul 19.2003 — Also...

The latest version of PHP is 4.3.2 (not including the beta of PHP 5) Basically what this tells me is that the host you are using is quite out of date. 4.0.4 was released in December of 2000! I'd find a new one -- one that keeps itself current. You are going to run into problems with all superglobals (including $_POST and $_GET)...
×

Success!

Help @Jonathan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...