当今天某ip访问时,自动记录这个ip到数据库!然后打开页面1给他看,如果这个ip再次访问的时候,就打开页面2,如果多次访问,都给显示页面2看!
万分感激!
<?php include ("config.php"); $link = mysql_connect("$dbhost","$dbuser","$dbpswd") or die ("连接数据库失败"); $info = nl2br($info); if ($ip != "none") { $fp = fopen("/home/mydata/ip.txt","r+"); //Unix系统的格式,若为windows格式,应为fopen("C:\\mydata\\ip.txt","r+"),设置为可读写 $data = addslashes (fread($fp,filesize(ip.txt))); } ?> <?php session_start(); function get_client_ip() //补充一下,有时候$REMOTE_ADDR;并不一定是真的ip //用HTTP_X_FORWARDED_FOR更真实一些 { global $_SERVER; if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; } elseif (isset($_SERVER["HTTP_CLIENT_IP"])) { $ip = $_SERVER["HTTP_CLIENT_IP"]; } else { $ip = $_SERVER["REMOTE_ADDR"]; } return $ip; } /*if (getenv(HTTP_X_FORWARDED_FOR)) { $ip = getenv('HTTP_X_FORWARD_FOR'); $host = gethostbyaddr($ip); } else { $ip = getenv('REMOTE_ADDR'); $host = gethostbyaddr($ip); }*/ // /*...*/里面是获得ip的另一种写法 $ip="get_client_ip()"; session_register($ip); string session_name(ip)
?>
<?php session_start(); boolean session_is_registered($ip) ...#判断ip是否在session中,若在访问页面2,不在访问页面1。用if...else...写就可以了,自己完成这部分吧 ?>