$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?
使用$_SERVER['REQUEST_TIME']
(或$_SERVER['REQUEST_TIME_FLOAT']
如果您使用的是PHP 5.4.0及更高版本)。
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.