Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.