- 论坛徽章:
- 0
|
十五写了一个记录来访信息的东东,请大侠们斧正!
初始化来访记录
- <?php
- $host="localhost";
- $login="root";
- $password="";
- $dbname="hent";
- $rectotal=100;
- $connect=mysql_connect($host,$login,$password);
- $selectdb=mysql_select_db($dbname,$connect);
- $sql="INSERT INTO guestrecord (ip,port,time,browser) VALUES ('0.0.0.0',0,'0000-00-00 00:00:00','-')";
- for($i=0;$i<$rectotal;$i++)
- {
- $result=mysql_query($sql,$connect);
- }
- printf("<br>用户访问记录<b> %d </b>条 初始化完毕!<br>",$rectotal);
- ?>
复制代码
记录来访者信息
- <?
- $host="localhost";
- $login="root";
- $password="";
- $dbname="hent";
- $connect=mysql_connect($host,$login,$password);
- $selectdb=mysql_select_db($dbname,$connect);
- /* 以下为来宾访问记录 */
- $ip=$_SERVER["REMOTE_ADDR"];
- $port=$_SERVER["REMOTE_PORT"];
- $time=date("Y-m-d H:i:s");
- $browser=$_SERVER["HTTP_USER_AGENT"];
- //得到来访者信息
- $sql="INSERT INTO guestrecord (ip,port,time,browser) VALUES ('$ip','$port','$time','$browser')";
- $result=mysql_query($sql,$connect);
- //记录来访者信息
- $sql="SELECT * FROM guestrecord ORDER BY rec LIMIT 1";
- $result=mysql_query($sql);
- $guestrow=mysql_fetch_array($result);
- $firstrec=$guestrow["rec"];
- $sql="DELETE FROM guestrecord WHERE rec=$firstrec LIMIT 1";
- $result=mysql_query($sql,$connect);
- //删除访问最老的一条记录
- ?>
复制代码
附图 |
|