Jump to content

Ip-Address's


joeysarsenal

Recommended Posts

Yes, there is a way.

 

Your going to have to know how to get their IP address and the date

$ip = $_SERVER['REMOTE_ADDR'];
$date = date("Y-m-d");

 

Now your going to have to know how to write it to a file.

http://www.tizag.com/phpT/filewrite.php

Link to comment
https://forums.phpfreaks.com/topic/75727-ip-addresss/#findComment-383231
Share on other sites

Yes, there is a way.

 

Your going to have to know how to get their IP address and the date

$ip = $_SERVER['REMOTE_ADDR'];
$date = date("Y-m-d");

 

Now your going to have to know how to write it to a file.

http://www.tizag.com/phpT/filewrite.php

 

thats the example they had at that site. With other information to open and overwrite. But i think this one is more revelant

"

 

$myFile = "testFile.txt";

$fh = fopen($myFile, 'w') or die("can't open file");

$stringData = "Bobby Bopper\n";

fwrite($fh, $stringData);

$stringData = "Tracy Tanner\n";

fwrite($fh, $stringData);

fclose($fh);"

 

<?php
$ip = $_SERVER['REMOTE_ADDR'];//variable ? 
$date = date("Y-m-d"); //variable ? 

$myFile = "log.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $ip";
fwrite($fh, $stringData);
$stringData = "$date";
fwrite($fh, $stringData);
fclose($fh);"
?>

cant really test it here. No Xampp on these comps.

 

Link to comment
https://forums.phpfreaks.com/topic/75727-ip-addresss/#findComment-383236
Share on other sites

You have a few errors

 

<?php
$ip = $_SERVER['REMOTE_ADDR'];//variable ? 
$date = date("Y-m-d"); //variable ? 

$myFile = "log.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $ip;
fwrite($fh, $stringData);
$stringData = $date;
fwrite($fh, $stringData);
fclose($fh);
?>

Link to comment
https://forums.phpfreaks.com/topic/75727-ip-addresss/#findComment-383239
Share on other sites

before you do this, that will fail because you have the 'w type of opening which will wipe the file clean on each rewrite, use the 'a' instead of w and you be better.  also you have no delimiter in there, and you can write it all in 1 srting try

<?php
$ip = $_SERVER['REMOTE_ADDR'];//variable ? 
$date = date("Y-m-d"); //variable ? 

$myFile = "log.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $date.", ".$ip."\r\r\n";
fwrite($fh, $stringData);
fclose($fh);
?>

that has a delimiter and it spaces it like

Date, IP

Date, IP

for ease of reading.

Link to comment
https://forums.phpfreaks.com/topic/75727-ip-addresss/#findComment-383243
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.