我的论坛源代码(五)

2015-01-24信息快讯网
okey.php主要处理用户登录和发布的信息处理


<?
if ($username)                       //是否有用户信息
$useinfo=$username."|".$userpass;
setcookie("FlyFoxNet",$useinfo,time()+3600);   

if ($d==q) setcookie("FlyFoxNet");     //如果是退出的话,把COOKIE置为空
?>
<HTML><HEAD><TITLE>发表文章</TITLE>
<LINK href="js/cpcw.css" rel=stylesheet /LINK>
<?
include "linkfox.inc.php";
include "info.inc.php";
function postf($useinfo,$title,$message)        //发帖信息处理
{
       $query="select * from foxbbs order by id desc limit 1";
       $row=@mysql_query($query);
       $info=@mysql_fetch_array($row);
       if ($useinfo[2]==$info[1]&&$title==$info[3])         //检查最近一条信息是否和当前信息一样。
          echo "<script language='JavaScript'> alert('请勿重复发帖,谢谢合作!'); </script>";
       else{
         $time=date(Y年n月j日G时i分);
         $filename=date(YmjGis);               //文件名取当前的时间
         $gip=getenv("REMOTE_ADDR");        //写入信息
         $query="insert into foxbbs (usename,ftbq,title,ftdate,mesname,djnum,hfnum,ip) values ('".$useinfo[0]."','".$useinfo[14]."','".$title."','".$time."','".$filename."',1,0,'".$gip."')";
         $req=@mysql_query($query);
         if ($req) {                      //如果写入成功,则给用户发帖数加一,建立内容文件
            $query="select ftnum from useinfo where usename='".$useinfo[0]."'";
            $req=@mysql_query($query);
            $ftnum=@mysql_fetch_array($req);
            $ftnum=$ftnum[0]+1;
            $query="update useinfo set ftnum='$ftnum' where usename='".$useinfo[0]."'";
            $req=@mysql_query($query);
            $ft=$filename;
            $fp=fopen($ft,"w");         //把所有的"<",">"符号转换成"<","&rt;"可以去除HTML标记,好像有个函数可以直接去除,但我记不到了,也没在参考手册里查到,所以用个笨法子了。
            $message=str_replace("<","<",str_replace(">",">",$message));
            $message=nl2br($message);    //先去除符号再变换行,免得换行符也变成字符显示出来。
            $f=fputs($fp,$message);
            $fp=@fclose($fp);
            echo "<script language='JavaScript'> alert('".$useinfo[2]."!恭喜你,发贴成功!'); </script>";
            }
         else {
            echo "<script language='JavaScript'> alert('非常报歉,因数据库原因,你的帖子没能保存!'); </script>";
              }
        }

}
function userr($username,$userpass,$title,$message)        //用户信息校验函数
{
    $query="select * from useinfo where usename='".$username."'";
    $req=mysql_query($query);
    $useinfo=mysql_fetch_array($req);
     if ($useinfo[0]==$username)
     {
//如果通过校检就调用信息处理函数
       if ($userpass==$useinfo[1])  {postf($useinfo,$title,$message);return $useinfo;}
       else {
       echo "<script language='JavaScript'> alert('密码不正确,请检查!'); </script>";
       echo "<meta HTTP-EQUIV='REFRESH' CONTENT='2;URL=post.php'>";
       }
     }
     else
     {
       echo "<script language='JavaScript'> alert('用户不存在,请确认已注册!'); </script>";
     }
}
?>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<meta HTTP-EQUIV="REFRESH" CONTENT="2;URL=foxbbs.php">
</head><body topmargin="0">
<?
$tem=$HTTP_COOKIE_VARS[FlyFoxNet];
$temp=explode("|",$tem);
$cookiem=$temp[0];
$useinfo=cuser($cookiem,$action);
if (isset($message))
{
  if($username)
  {
     $useinfo=userr($username,$userpass,$title,$message);
  }
  else if($useinfo) {
     userr($useinfo[0],$useinfo[1],$title,$message);
     }
  else {echo "<script language='JavaScript'> alert('你不是合法用户,不能在此论坛发帖!'); </script>";}

}
if ($d==q)
{
echo "<script language='JavaScript'> alert('你已退出登录状态,将以游客身份返回论坛'); </script>";
}
?>
<br><br><br><br><br>
<div align="center"><a href=foxbbs.php>如果系统未自动返回页面,请点击这里反回.</a></div>
</body>
</html> 
©2014-2024 dbsqp.com