Reputation: 1
$myFile = "Test.txt";
$fh = fopen($myFile, 'r+') or die("can't open file");
fwrite($fh, $_SERVER['REMOTE_HOST']);
fclose($fh);
echo $_SERVER['REMOTE_ADDR'];
I need to send this page to a person and get back his IP and connection date and time as you can see I know how to get the IP and save it to the test file but I also need to know when this IP connect to the page(date and time).
How I can do that?
Upvotes: 0
Views: 84
Reputation: 5622
use date();
function to capture date and time
example:
echo date('d.m.Y h:i:s');
In your case:
$myFile = "Test.txt";
$fh = fopen($myFile, 'a+') or die("can't open file");
fwrite($fh, $_SERVER['REMOTE_ADDR']);
fwrite($fh, date('d.m.Y h:i:s').PHP_EOL);
fclose($fh);
echo $_SERVER['REMOTE_ADDR'].'<br />';
echo date('d.m.Y h:i:s');
Notice a+
paramether in fopen function.
Upvotes: 0
Reputation: 174718
Use $_SERVER['REQUEST_TIME']
(or $_SERVER['REQUEST_TIME_FLOAT']
if you have PHP 5.4.0 and above).
Upvotes: 1