1,php记录用户的访问记录
<?php //用户访问记录 $address = $_SERVER['REMOTE_ADDR']; $referer = $_SERVER['HTTP_REFERER']; $browser = $_SERVER['HTTP_USER_AGENT']; $file = fopen("log.html", "a"); $time = date("H:i dS F"); fwrite( $file, "<b>时间:</b> $time<br>" ); if( $address != null) { fwrite( $file, "<b>IP Address:</b> $address <br>"); } if( $referer != null) { fwrite( $file, "<b>来源:</b> $referer<br>"); } fwrite( $file, "<b>浏览器:</b> $browser<br/><hr>"); fclose($file); ?>
这里顺便分享一个输出文件修改时间的代码,如下:
<?php $lastmod = filemtime($_SERVER['SCRIPT_FILENAME']); echo '文件的最后更新时间为: ' . date('l d F Y, at H:i:s T', $lastmod) . '.'; ?>