PHP ip logger

kloaknet

New Member
Messages
1
Reaction score
0
Points
0
Hi there!

i want to incorporate this script in my web page:

<?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);

?>

the rights i gave to the ips.txt file is 777 so that shouldn't be the problem, but it is not working. Are some php funtions blocked?
 

ah-blabla

New Member
Messages
375
Reaction score
7
Points
0
The output is wrong, i.e. no IP address... (I had to test it myself to check -- it is helpful to say exactly WHAT isn't working when you are requesting help -- it saves a lot of time...)

As I said I just tested it myself: the problem is you can't get an IP address using:
Code:
$REMOTE_ADDR
instead use:
Code:
$_SERVER['REMOTE_ADDR']

Edit://
Here's a good link for getting user and request data, in case you need it.
http://php.net/manual/en/reserved.variables.server.php
 
Last edited:

Gouri

Community Paragon
Community Support
Messages
4,565
Reaction score
245
Points
63
Register globals are off

To get ip address you have to use $_SERVER['REMOTE_ADDR'];

Why don't you use mysql table to store that is good option.

EDIT:
ah-blabla you beat me.
 
Last edited:
Top