Home > Programming > Recording IP address of Visitor

Recording IP address of Visitor

January 18th, 2009

Problem

You want to do a quick record of the ip address of the visitor to your website. You do not need any exotic database. Just a quick record of the ip address so that you can know if they are causing spam to your website.

Solution

$ip = $REMOTE_ADDR;

$myFile = “testFile.txt”;
$fh = fopen($myFile, ‘a’) or die(“can’t open file”);
$stringData =” “. $ip .” “;
fwrite($fh, $stringData);
fclose($fh);

Explanation

The visitors’ ip address will be recorded usingĀ  $ip = $REMOTE_ADDR;

The statement below that will be used to store the ip address in a file.

Programming

  1. No comments yet.
  1. No trackbacks yet.