Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log IP with php

Tags:

php

ip

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?

like image 969
Mat Avatar asked Dec 05 '25 13:12

Mat


1 Answers

The variable is

$_SERVER['REMOTE_ADDR']

so you need to change yours to

$v_ip = $_SERVER['REMOTE_ADDR'];
like image 97
Lee Armstrong Avatar answered Dec 09 '25 08:12

Lee Armstrong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!