Mat
Mat

Reputation: 23

log IP with php

i found this script online:

<?php
$v_ip = $REMOTE_ADDR; $v_date = date("l d F H:i:s");

$fp = fopen("ips.txt", "a"); fputs($fp, "IP: $v_ip - DATE: $v_date\n\n"); fclose($fp);

?>

creating the entry works - however, the IP is not displayed. the entries created look like this:

IP: - DATE: Wednesday 09 March 03:36:15

IP: - DATE: Wednesday 09 March 03:36:41

what's the problem?

Upvotes: 2

Views: 220

Answers (2)

Lee Armstrong
Lee Armstrong

Reputation: 11450

The variable is

$_SERVER['REMOTE_ADDR']

so you need to change yours to

$v_ip = $_SERVER['REMOTE_ADDR'];

Upvotes: 7

Codemwnci
Codemwnci

Reputation: 54944

You need to populate $REMOTE_ADDR with something. In this case, you would do

$REMOTE_ADDR  = $_SERVER['REMOTE_ADDR'];

or change your script to be

$v_ip = $_SERVER['REMOTE_ADDR']; $v_date = date("l d F H:i:s");

Upvotes: 3

Related Questions