PHP writes text file and C language very similar, with the function also consistent, read file with fopen, write file with fwrite, end with Fclose. Note that the new file is opened and written with the "W" identifier, the read file is identified with "R", and the original file continues to be written with the "a" identifier
, while the Windows line break is "RN", and the Linux newline character is "n"
PHP record IP function is $_server["REMOTE_ADDR"]
PHP Gets the current time function date ("Y-m-d h:i:s", Times ())
PHP Gets the URL function $_server[' http_referer ' first to determine whether it is a null value, that is, with isset to judge, such as we directly from the browser to enter the URL will not have a URL record, the final code is very simple, as follows:
| The code is as follows |
Copy Code |
$ip = $_server["REMOTE_ADDR"]; $time = Date ("Y-m-d h:i:s", Time ()); $from = "; if (Isset ($_server[' http_referer ')) { $from = $_server[' http_referer '); } $myfile = ' wtndata/statistic.txt '; $str = "ip=". $ip. "' from= '". $from. "' Time= '". $time. "' RN "; $file _pointer = fopen ($myfile, "a"); Fwrite ($file _pointer, $STR); Fclose ($file _pointer); |
http://www.bkjia.com/PHPjc/444738.html www.bkjia.com true http://www.bkjia.com/PHPjc/444738.html techarticle PHP writes text file and C language very similar, with the function also consistent, read file with fopen, write file with fwrite, end with Fclose. Note that the new file is opened and written with " ...