📄 fun.php
字号:
<?php
////////////////////////////////////////////////////////////////////////////////////////////////////////
function display_head()
{
$chatroom_name=db("get","files/system.php",1,"chatroom_name",2);
?>
<html><head><title><?echo$chatroom_name;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="index.files/css.css" type="text/css"></head>
<body bgcolor="#ffffff"><center>
<table width=296 height=417 border=0 cellspacing=0 cellpadding=0>
<tr><td colspan=3 height=259><img src="index.files/login_r2_c2.gif" border=0 width=296 height=259></td></tr>
<tr><td width=10 height=147><img src="index.files/login_r3_c2.gif" border=0 width=10 height=147></td>
<td width=277 height=147 align=center valign=middle>
<?
}
function display_foot()
{
?>
</td><td width=9 height=147><img src="index.files/login_r3_c4.gif" border=0 width=9 height=147></td></tr>
<tr><td colspan=3 height=11><img src="index.files/login_r4_c2.gif" border=0 width=296 height=11></td></tr>
</table>
</table></center></body></html>
<?
}
function message($content,$mode="",$url="")
{
if($mode=="")
{
echo $content;
}
if($mode=="error")
{
echo $content." <a href=\"javascript:history.go(-1)\">[ 返回 ]</a>";
}
if($mode=="return" && $url!="")
{
echo "<head><meta http-equiv=\"refresh\" content=\"2;URL=".$url."\"></head>\n";
echo "".$content." (<a href=".$url.">两秒钟将自动刷新</a>)";
}
}
function limitstr($str,$limitlen)
{
$len=strlen($str);
if($len>=$limitlen)
{
$str=substr($str,0,$limitlen-2);
$str.=" ..";
return $str;
}
else
return $str;
}
function writeF($filename,$contents,$mode)
{
$file=@fopen($filename,$mode);
@flock($file,3);
@fwrite($file,$contents);
@fclose($file);
}
function replace($filename,$rownum,$newrow)
{
$row=file($filename);
$all="";
for($i=0;$i<$rownum;$i++)
$all.=chop($row[$i])."\n";
$all.=$newrow;
for($i=$rownum+1;$i<count($row);$i++)
$all.=chop($row[$i])."\n";
writeF($filename,$all,"w");
}
function getnum($filename)
{
$row=file($filename);
return chop($row[0]);
}
function delrow($filename,$rownum)
{
$row=file($filename);
$all="";
for($i=0;$i<$rownum;$i++)
$all.=chop($row[$i])."\n";
for($i=$rownum+1;$i<count($row);$i++)
$all.=chop($row[$i])."\n";
writeF($filename,$all,"w");
}
function safe($msg)
{
$msg=str_replace("|", "|", $msg);
$msg=str_replace("&", "&", $msg);
$msg=str_replace(">", ">", $msg);
$msg=str_replace("<", "<", $msg);
$msg=str_replace("'", "'", $msg);
$msg=str_replace("\"", """, $msg);
$msg=str_replace("[br]", "<br>", $msg);
return $msg;
}
function check_name_pass($str)
{
if(eregi("[|'\"]",$str))
return "no";
else
return "yes";
}
function db($method,$filename,$tag_col,$tag,$target_col,$target="")
{
$row=file($filename);
for($i=1;$i<count($row);$i++)
{
$sub=explode("|",$row[$i]);
if($tag==$sub[$tag_col])
{
//操作接口
if($method=="get")
return $sub[$target_col];
if($method=="getline")
return $row[$i];
if($method=="put")
{
$all="";
$newrow="";
for($j=0;$j<$target_col;$j++)
$newrow.=$sub[$j]."|";
$newrow.=$target."|";
for($j=$target_col+1;$j<count($sub);$j++)
{
if($j==(count($sub)-1)) $newrow.=chop($sub[$j])."\n";
else $newrow.=$sub[$j]."|";
}
for($j=0;$j<$i;$j++)
$all.=chop($row[$j])."\n";
$all.=$newrow;
for($j=$i+1;$j<count($row);$j++)
$all.=chop($row[$j])."\n";
writeF($filename,$all,"w+");
return true;
}
}
}
return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function login($username,$userpass,$longin_method)
{
if(chop($longin_method)=="") $longin_method="local";
$username=safe($username);
$userpass=safe($userpass);
if(chop($username)=="" || chop($userpass)=="")
{
display_head();
display_login();
message("<font color=red>用户名和密码不能为空</font>","","");
display_foot();
exit;
}
$row=file("files/userdata.php");
for($i=1;$i<count($row);$i++)
{
$sub=explode("|",$row[$i]);
if($username==$sub[1])
{
$user_found="yes";
if( ($longin_method=="local" && $userpass==$sub[2]) || ($longin_method=="remote" && $userpass==md5($sub[2]) ) )
{
setcookie("username",$username,time()+864000);
setcookie("logined","yes",time()+864000);
display_head();
message("正在登陆聊天室!","return","index.php");
display_foot();
exit;
}
else
{
display_head();
display_login();
message("<font color=red>用户密码错误!请检查密码输入</font>");
display_foot();
exit;
}
break;
}
}
if($user_found!="yes")
{
$newuser="|".$username."|".$userpass."||\n";
writeF("files/userdata.php",$newuser,"a+");
setcookie("username",$username,time()+864000);
setcookie("logined","yes",time()+864000);
display_head();
message("正在登陆聊天室!","return","index.php");
display_foot();
exit;
}
}
function checklogin()
{
global $username;
global $logined;
if($logined=="yes" && $username!="")
return "yes";
if($logined=="no" || $logined=="" || $username=="")
return "no";
}
function display_login()
{
if(checklogin()=="yes")
{
message("<font color=red>您已经登陆了!</font>");
exit;
}
?>
<form name="login" method="post" action="index.php?action=login">
<table width=250 border=0 cellspacing=0 cellpadding=0>
<tr><td width=80 height=30>用户名称</td>
<td width=170 height=30 align=left>
<input size=10 type="text" name=user class="input" onMouseOver ="this.style.backgroundColor='#F0F1FF'" onMouseOut ="this.style.backgroundColor=''"></td></tr>
<tr><td width=80 height=30 align=left>用户密码</td>
<td width=170 height=30>
<input size=10 type="password" name=pass class="input" onMouseOver ="this.style.backgroundColor='#F0F1FF'" onMouseOut ="this.style.backgroundColor=''">
<input type="submit" name="Submit" value="登陆" class="button" onMouseOver ="this.style.backgroundColor='#EEF7FF'" onMouseOut ="this.style.backgroundColor=''"></td></tr>
<tr><td colspan=2> <font color=#666666>游客可直接登陆,系统将自动注册!</font> </td></tr>
</table></form>
<?
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -