Topic: HOW TO COLLECT IP ADDRESS WITH PHP

HI
how do i collect people who fill out form ip address so i can control spam .
i am currently is using php form to contact me how ever i want to also add there unique ip address when the form is sent to be
here is my file contact.php


<h1><img src='03.png'> Contact Us</h1>

<img src='bigEmail.png' width="170" height="178" style='float:right'>
<img src='customerservice.JPG' width="300" height="300" style='float:right'>
<form name=contactus method=post action='send.php'>
<input type=hidden name=feedback value=1>
Name: <span class=req>*</span><br>
&nbsp;<input type=text name=name style='width:250px'>
<br>
Phone: <span class=req>*</span><br>
&nbsp;<input type=text name=phone style='width:250px'>
<br>Email: <span class=req>*</span><br>
&nbsp;<input type=text name=email style='width:250px'>
<br><br>Your comments: <span class=req>*</span><br>
&nbsp;<textarea name=comment style='width:350px' rows=4></textarea>
<br>
<input type=button value='Send &gt;&gt;'  onclick='if (contactusOK()) document.contactus.submit()'>
</form>


and here is my send.php

<?
if (isset($_POST['name']) && !isset($_POST['freequote'])) {
  $MSG = 'Contact Us:<br>';
  $MSG .= (isset($_POST['name']))? 'Name = '.$_POST['name']."<br>" : '';
  $MSG .= (isset($_POST['phone']))? 'Phone = <span dir=ltr>'.$_POST['phone']."</span><br>" : '';
  $MSG .= (isset($_POST['email']))? 'Email = <span dir=ltr>'.$_POST['email']."</span><br>" : '';
  $MSG .= (isset($_POST['comment']))? 'Comments = '.nl2br($_POST['comment'])."<br>" : '';
  $MSG = "<div>$MSG</div>";
  $headers  = "MIME-Version: 1.0\n";
  $headers .= "Content-type: text/html; charset=windows-1255\n";
  $headers .= "From: Movers Community <info@moverscommunity.com>\n";
  $st = mail('avidanbanks@gmail.com moversleads@gmail.com', 'From website', $MSG, $headers);
  header('location: thanks.php');
  exit();

were do i put a code to collect the person unique ip address and send it to me so i can see who is on my site ?

please advise

Vote up Vote down

Re: HOW TO COLLECT IP ADDRESS WITH PHP

Hi,

$_SERVER['REMOTE_ADDR']

This picks up the IP address of the user sending the form.

Here's how you can add it to your script, find this part:

$st = mail('avidanbanks@gmail.com moversleads@gmail.com', 'From website', $MSG, $headers);

Change it to:

$subject = "From Website: ".$_SERVER['REMOTE_ADDR'];
$st = mail('avidanbanks@gmail.com moversleads@gmail.com', $subject, $MSG, $headers);

Dean


abanksob1 wrote:

HI
how do i collect people who fill out form ip address so i can control spam .
i am currently is using php form to contact me how ever i want to also add there unique ip address when the form is sent to be
here is my file contact.php


<h1><img src='03.png'> Contact Us</h1>

<img src='bigEmail.png' width="170" height="178" style='float:right'>
<img src='customerservice.JPG' width="300" height="300" style='float:right'>
<form name=contactus method=post action='send.php'>
<input type=hidden name=feedback value=1>
Name: <span class=req>*</span><br>
&nbsp;<input type=text name=name style='width:250px'>
<br>
Phone: <span class=req>*</span><br>
&nbsp;<input type=text name=phone style='width:250px'>
<br>Email: <span class=req>*</span><br>
&nbsp;<input type=text name=email style='width:250px'>
<br><br>Your comments: <span class=req>*</span><br>
&nbsp;<textarea name=comment style='width:350px' rows=4></textarea>
<br>
<input type=button value='Send &gt;&gt;'  onclick='if (contactusOK()) document.contactus.submit()'>
</form>


and here is my send.php

<?
if (isset($_POST['name']) && !isset($_POST['freequote'])) {
  $MSG = 'Contact Us:<br>';
  $MSG .= (isset($_POST['name']))? 'Name = '.$_POST['name']."<br>" : '';
  $MSG .= (isset($_POST['phone']))? 'Phone = <span dir=ltr>'.$_POST['phone']."</span><br>" : '';
  $MSG .= (isset($_POST['email']))? 'Email = <span dir=ltr>'.$_POST['email']."</span><br>" : '';
  $MSG .= (isset($_POST['comment']))? 'Comments = '.nl2br($_POST['comment'])."<br>" : '';
  $MSG = "<div>$MSG</div>";
  $headers  = "MIME-Version: 1.0\n";
  $headers .= "Content-type: text/html; charset=windows-1255\n";
  $headers .= "From: Movers Community <info@moverscommunity.com>\n";
  $st = mail('avidanbanks@gmail.com moversleads@gmail.com', 'From website', $MSG, $headers);
  header('location: thanks.php');
  exit();

were do i put a code to collect the person unique ip address and send it to me so i can see who is on my site ?

please advise

Vote up Vote down