函数总结
一,记录用户登录信息:
1function recordip($name){ $fp=fopen("record/ip.txt","a+");
2fseek($fp,0,SEEK_END);
3$nowtime=date(YÄêmÔÂjÈÕ);
4$ip=getenv("REMOTE_ADDR");
5$str="<tr><td>用户名</td><td>".$name;
6$str=$str."</td><td>IP:</td><td>".$ip;
7$str=$str."</td><td>登录时间:</td><td>".$nowtime;
8$str=$str."</td><td>登录论坛</td><td>成功</td></tr>";
9$write=fwrite($fp,$str);
10fclose($fp);
11}
12
二,读取用户登录信息2fseek($fp,0,SEEK_END);
3$nowtime=date(YÄêmÔÂjÈÕ);
4$ip=getenv("REMOTE_ADDR");
5$str="<tr><td>用户名</td><td>".$name;
6$str=$str."</td><td>IP:</td><td>".$ip;
7$str=$str."</td><td>登录时间:</td><td>".$nowtime;
8$str=$str."</td><td>登录论坛</td><td>成功</td></tr>";
9$write=fwrite($fp,$str);
10fclose($fp);
11}
12
1function seeinfo()
2{
3$filename="record/ip.txt";
4$fd=fopen($filename,"r");
5$string=fread($fd,filesize($filename));
6fclose($fd);
7$string=str_replace("\n","<br>",$string);
8$string=str_replace("\'","",$string);
9echo $string;
10}
11
三,登录,注册验证2{
3$filename="record/ip.txt";
4$fd=fopen($filename,"r");
5$string=fread($fd,filesize($filename));
6fclose($fd);
7$string=str_replace("\n","<br>",$string);
8$string=str_replace("\'","",$string);
9echo $string;
10}
11
注册处理:
1function check($name,$pwd){ //登录验证
2$sql="select * from users where uname='$name'";
3$result=mysql_query($sql);
4$num=mysql_num_rows($result);
5if($answer=mysql_fetch_array($result))
6{
7 if($pwd==$answer['pwd'])
8 {
9 $_SESSION['username']=$name;
10 updatestatus($name);
11 $lasttime=date("Y-n-j h:i:s");
12 echo "<script>alert('登录成功');";
13 echo "this.location.href='bbs.php';</script>";
14 }
15 else
16 {
17 echo "<script>alert('密码有误');";
18 echo "this.location.href='login.php';</script>";
19 }
20}
21else
22{
23 echo "你尚未注册,请<a href=\"register.php\">注册</a>后再登录";
24}
25}
26function flag(){ //判断登录
27if(!isset($_SESSION['username']) && $_SESSION['username']==""){
28echo "你尚未登录,不能查看此页";
29exit;
30}
31}
32function checkreg($uid,$pwd,$pwd1,$email){ //注册
33if($uid==""){
34echo "用户名不能为空";
35exit;
36}
37if($pwd==""){
38echo "密码不能为空";
39exit;
40}
41if($pwd1!=$pwd){
42echo "两次密码不一致";
43exit;
44}
45if(strstr($uid,"@")){
46echo "不正确的邮箱格式";
47exit;
48}
49$sql="select * from users where uname='$uid'";
50print_r($sql);
51$result=mysql_query($sql);
52$nums=mysql_num_rows($result);
53echo $nums;
54$uid=htmlspecialchars($uid);
55$pwd=md5($pwd);
56$lasttime=date("Y-n-j h:i:s");
57echo $lasttime;
58if(empty($nums)){
59$sql="insert into users(uname,pwd,email) values('$uid','$pwd','$email')";
60print_r($sql);
61$result=mysql_query($sql);
62 if($result){
63 $_SESSION['username']=$uid;
64 echo $uid;
65 updatestatus($uid);
66 echo "<script>alert('注册成功');";
67echo "this.location.href='bbs.php';</script>";
68 }
69 else
70 {
71 echo "<script language=javascript>alert('注册失败');";
72 echo "javascript:history.go(-1)</script>";
73 }
74}
75else
76{
77echo "此用户名已存在,请用其它的用户名<a href=\"register.php\">注册</a>";
78}
79}
80function updatestatus($name){
81//更新登录状态
82$lasttime=date("Y-n-j h:i:s");
83$ip=getenv("REMOTE_ADDR");
84$sql="update users set status=status+1 where uname='$name'";
85print_r($sql);
86$result=mysql_query($sql);
87$sql="select * from useronline where uname='$name'";
88$result=mysql_query($sql);
89$num=mysql_num_rows($result);
90if($num>0)
91{
92$now=date("Y-n-j h:i:s");
93$diff=strtotime($now) - strtotime($last);
94echo $diff;
95$sql="update useronline set logintime='$nowtime' where uname='$name'";
96print_r($sql);
97$result=mysql_query($sql);
98}
99else
100{
101$sql="insert into useronline(uname,logintime,ip) values('$name','$lasttime','$ip') ";
102$result=mysql_query($sql);
103}
104}
2$sql="select * from users where uname='$name'";
3$result=mysql_query($sql);
4$num=mysql_num_rows($result);
5if($answer=mysql_fetch_array($result))
6{
7 if($pwd==$answer['pwd'])
8 {
9 $_SESSION['username']=$name;
10 updatestatus($name);
11 $lasttime=date("Y-n-j h:i:s");
12 echo "<script>alert('登录成功');";
13 echo "this.location.href='bbs.php';</script>";
14 }
15 else
16 {
17 echo "<script>alert('密码有误');";
18 echo "this.location.href='login.php';</script>";
19 }
20}
21else
22{
23 echo "你尚未注册,请<a href=\"register.php\">注册</a>后再登录";
24}
25}
26function flag(){ //判断登录
27if(!isset($_SESSION['username']) && $_SESSION['username']==""){
28echo "你尚未登录,不能查看此页";
29exit;
30}
31}
32function checkreg($uid,$pwd,$pwd1,$email){ //注册
33if($uid==""){
34echo "用户名不能为空";
35exit;
36}
37if($pwd==""){
38echo "密码不能为空";
39exit;
40}
41if($pwd1!=$pwd){
42echo "两次密码不一致";
43exit;
44}
45if(strstr($uid,"@")){
46echo "不正确的邮箱格式";
47exit;
48}
49$sql="select * from users where uname='$uid'";
50print_r($sql);
51$result=mysql_query($sql);
52$nums=mysql_num_rows($result);
53echo $nums;
54$uid=htmlspecialchars($uid);
55$pwd=md5($pwd);
56$lasttime=date("Y-n-j h:i:s");
57echo $lasttime;
58if(empty($nums)){
59$sql="insert into users(uname,pwd,email) values('$uid','$pwd','$email')";
60print_r($sql);
61$result=mysql_query($sql);
62 if($result){
63 $_SESSION['username']=$uid;
64 echo $uid;
65 updatestatus($uid);
66 echo "<script>alert('注册成功');";
67echo "this.location.href='bbs.php';</script>";
68 }
69 else
70 {
71 echo "<script language=javascript>alert('注册失败');";
72 echo "javascript:history.go(-1)</script>";
73 }
74}
75else
76{
77echo "此用户名已存在,请用其它的用户名<a href=\"register.php\">注册</a>";
78}
79}
80function updatestatus($name){
81//更新登录状态
82$lasttime=date("Y-n-j h:i:s");
83$ip=getenv("REMOTE_ADDR");
84$sql="update users set status=status+1 where uname='$name'";
85print_r($sql);
86$result=mysql_query($sql);
87$sql="select * from useronline where uname='$name'";
88$result=mysql_query($sql);
89$num=mysql_num_rows($result);
90if($num>0)
91{
92$now=date("Y-n-j h:i:s");
93$diff=strtotime($now) - strtotime($last);
94echo $diff;
95$sql="update useronline set logintime='$nowtime' where uname='$name'";
96print_r($sql);
97$result=mysql_query($sql);
98}
99else
100{
101$sql="insert into useronline(uname,logintime,ip) values('$name','$lasttime','$ip') ";
102$result=mysql_query($sql);
103}
104}