<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_22578"> <div class="blockcode"> <div id="code_Yrm"><ol> <li> <li><?php<li> //文件名字<li> $filename = "ip.txt";<li> if (isset($_SERVER['HTTP_CLIENT_IP']))<li> {<li> $clientip = $_SERVER['HTTP_CLIENT_IP'];<li> }elseif (isset($_SERVER['HTTP_X_FORWARD_FOR']))<li> {<li> $clientip = $_SERVER['HTTP_X_FORWARD_FOR'];<li> }else<li> {<li> $clientip = $_SERVER['REMOTE_ADDR'];<li> }<li> //打开文件(文件不存在自动建立)<li> if (!$fp = fopen($filename, "a "))<li> {<li> echo "不能打开文件$";<li> exit;<li> }<li> //写入的时候还判断是否已经有重复数据<li> while(!feof($fp))<li> {<li> $line = fgets($fp);<li> if($line == ($clientip."n"))<li> { <li> exit; //有重复数据就退出;<li> }<li> }<li> // 写入文件<li> if(!fwrite($fp,$clientip."n"))<li> {<li> echo "不能写入到文件$filename" ;<li> exit;<li> }<li> //已经完成写入文件<li> fclose($fp);<li> ?></li> </ol></div> <em onclick="copycode($('code_Yrm'));">复制代码</em> </div> </td></tr></table> <div id="comment_22578" class="cm"> </div> <div id="post_rate_div_22578"></div> <br><br>