PHP的bbs实现之一

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

0.sql
CREATE TABLE user_log (
  log_id int(10) NOT NULL auto_increment,
  nicker        varchar(20),
  password varchar(10) NOT NULL,
  log_count  int(10),
  last_time varchar(20),
  last_ip       varchar(30),
  arc_count int(10),
  gender enum('M','W') DEFAULT 'M' NOT NULL,
  level         int(1),
  right         varchar(10),
  exp_count     int(10),
  PRIMARY KEY (log_id),
  UNIQUE log_id (log_id)
);
CREATE TABLE user_attr (  
  log_id        int(10) NOT NULL,
  realname varchar(20),
  email         varchar(40),
  address varchar(50),
  birthday  varchar(20),
  oicq          int(8),
  last_time varchar(20),
  homepage      varchar(50),
  merriage enum('Y','N') DEFAULT 'N' NOT NULL,
  edu_level varchar(8),
  edu_school    varchar(30),
  province      varchar(20),
  city          varchar(20),
  postalcode    int(6),
  fond          varchar(8),  
  present       text,
  PRIMARY KEY (log_id),
  UNIQUE log_id (log_id)
);
CREATE TABLE user_online (
  log_id int(10) NOT NULL,
  nicker        varchar(20),
  log_count  int(10),
  log_time varchar(20),
  log_ip        varchar(30),
  arc_count int(10),
  gender enum('M','W') DEFAULT 'M' NOT NULL,
  level         int(1),
  right         varchar(10),
  exp_count     int(10),
  PRIMARY KEY (log_id),
  UNIQUE log_id (log_id)
);
1.register.php
<?
  include "common.inc.php";
function Checknicker($nicker) {            
  global $USER_LOG_TABLE;
  $SQL="SELECT nicker FROM $USER_LOG_TABLE WHERE nicker='$nicker'";
  $result=mysql_query($SQL) or die(mysql_error());
  $row=mysql_fetch_Array($result);
  $nicker=$row[nicker];
  return $nicker;
}
function AddUser() {
  global $USER_LOG_TABLE;
  global $id,$REMOTE_ADDR,$nicker;
  global $password, $log_count, $last_time,
          $last_ip, $arc_count, $gender, $level, $right,
          $exp_count;
  $last_time=date("Y:m:d");
  $log_count=0;
  $last_ip=$REMOTE_ADDR;
  $arc_count=0; 
  $level=9;                   
  $right='NONE';                
  $exp_count=100;                      
  $SQL="INSERT INTO $USER_LOG_TABLE (
          nicker, password,log_count,last_time,last_ip,arc_count,
          gender,level,right,exp_count) VALUES (
          '$nicker', '$password', '$log_count', '$last_time',
          '$last_ip', '$arc_count', '$gender', '$level', '$right','$exp_count')";
  mysql_query($SQL) or die(mysql_error());
  $SQL="SELECT log_id FROM $USER_LOG_TABLE WHERE nicker='$nicker'";
  $result=mysql_query($SQL) or die(mysql_error());
  $row=mysql_fetch_Array($result);
  $id=$row[log_id];
}                         
if ($Ok) {
  if (!$nicker) $error="用 户 名 不 能 为 空";
  if ((!isset($error)) and (!ereg("[_0-9a-z]*",$nicker))) $error="请 使 用 小 写 字 母"a-z",数 字 "0-9",和 下 划 线 "_"";
  if ((!isset($error)) and (strlen($nicker)<4)) $error="昵称的长度应大于3位";
  if ((!isset($error)) and (Checknicker($nicker))) $error="此 用 户 名 已 存 在";
  if ((!isset($error)) and (!$password)) $error="请 输 入 您 的 密 码";
  if ((!isset($error)) and ($password!=$password2)) $error="两 次 输 入 的 密 码 不 同";
  if (!isset($error)) {
    AddUser();
    header("Location: login_ok.php?id=$id\n");
  } else 
  {
    header("Location: login_error.php?error=$error\n");
  }
  exit;
}
include "header.inc.php";
$gender="M"
?>
<BODY>
<TABLE width=100% border=0 align=center>
  <TR class=myBlue>
    <TD height=25 align=center>
        <FONT class=myRed>
         <?echo "用 户 申 请 表"?>
        </FONT>
    </TD>
  </TR>
</TABLE>         
<hr color=red>
<FORM METHOD="POST" ACTION="<? echo $PHP_SELF; ?>">
  <TABLE width=80% border=1  align=center bgcolor=yellow>
    <TR class=myBlack bgcolor=green>
      <TD colspan=2 height=20 align=center>
          <FONT class=myYellow>
             请按照要求填写下列各项!
          </FONT>
      </td>
    </TR>                  
    <TR class=myBlack>
      <TD height=20 width=10% align=center class=myRed>昵 称:</TD>
      <TD height=20 width=72% align=left>
        <INPUT type=text name=nicker maxlength=20 value="<? echo $nicker; ?>" >
        <FONT class=myRed>
        长度不少于4位的字母数字和下划线
        </FONT>
      </TD>
    </TR> 
    <TR class=myBlack>
      <TD height=30 width=10% align=center class=myRed>性别:</TD>
      <TD height=30 width=70% align=left>
        <INPUT type=radio name=gender value="M" 
           <? echo ($gender=="M") ? "checked" : ""; ?>>
              <font class=myBlue>
                 俊男
              </font>  
        <INPUT type=radio name=gender value="W" 
           <? echo ($gender=="W") ? "checked" : ""; ?>>
               <font class=myBlue>
                美女
               </font>
        <FONT class=myRed>             
          &nbsp当心,别错了!
        </FONT>
      </TD>
    </TR> 
    <TR class=myBlack>
      <TD height=30 width=10% align=center class=myRed>
          密    码:
      </TD>
      <TD height=30 width=70%>
        <input type=password name="password" maxlength=8 > 
        <FONT class=myRed>
        一定要把它记牢了!进入社区的钥匙!
        </FONT>
      </TD>
    </TR>  
    <TR class=myBlack>
      <TD height=30 width=10% align=center class=myRed>
          重复密码:
      </TD>
      <TD height=30 width=70%>
        <input type=password name="password2" maxlength=8 >
        <FONT class=myRed>
        请再确认一下密码!
        </FONT>
      </TD>
    </TR>  
    <TR class=myBlack>
      <TD height=30 width=80% colspan=2 align=center class=myRed><BR>
        <INPUT type=reset  name=Start value=" 重置 " class=myBlack>                   
        <INPUT type=submit name=Ok value=" 发送 " class=myBlack>                   
        <INPUT type=button name=Back value=" 返回 " class=myBlack 
            onClick=JavaScript:history.back()>
      </TD>
    </TR>
  </TABLE>
</FORM>
<DIV class=myGreen align=center>
    <? echo $COPYRIGHT; ?>
</DIV>
<BR>
</BODY>
</HTML> 
2. common.inc
<?                                                                 
                                                                   
//数据库所在的主机地址,localhost是本机地址                        
  $MYSQL_HOSTNAME = "localhost";                                   
//数据库登录的用户名称                                             
  $MYSQL_USERNAME = "root";                                        
//数据库登录的密码                                                 
  $MYSQL_PASSWORD = "";                                            
//要登录的数据库的名称                                             
  $DATABASE = "goldenwind";                                        
//所有登录的用户名表                                               
  $USER_LOG_TABLE = "user_log";                                    
//用户的详细情况表                                                 
  $USER_ATTR_TABLE = "user_attr";                                  
//用户的详细情况表                                                 
  $USER_ONLINE_TABLE = "user_online";                              
                                                                   
//显示的版权信息                                                   
  $COPYRIGHT="<BR>Copyright &copy; 2000  [url]www.fecit.com[/url], ";          
  $COPYRIGHT.="All Rights Reserved<BR>飞思教育 版权所有!";        
                                                                   
//数据库的连接操作                                                 
  mysql_connect($MYSQL_HOSTNAME, $MYSQL_USERNAME, $MYSQL_PASSWORD);
  mysql_select_db($DATABASE) or die(mysql_error());                
                                                                   
?>               
3. login_error.php
<?                                                                            
  include "header.inc.php";                                                   
?>                                                                            
                                                                              
<HTML>                                                                        
<!--HTML的头定义-->                                                           
  <HEAD>                                                                      
    <META http-equiv="Content-Type" content="text/html; charset=gb2312">      
  </HEAD>                                                                     
                                                                              
<BODY>                                                                        
<!--滚动显示提示信息-->                                                       
<marquee scrolldelay="165" class=myYellow bgcolor=green>                      
   欢迎光临金风社区&nbsp&nbsp&nbsp&nbsp&nbsp                                  
   这是我们的PHP乐园&nbsp&nbsp&nbsp&nbsp&nbsp                                 
   希望您能喜欢它~&nbsp&nbsp&nbsp&nbsp&nbsp                                  
</marquee>                                                                    
                                                                              
<!--显示一面迎风飘扬的旗帜作为提示信息-->                                     
<img src="images/flag.gif" align=left>                                        
<!--显示本页面的大标题-->                                                     
<h2 align=center color=red>                                                   
  错误信息!                                                                  
</h2>                                                                         
<!--显示一条红色的水平的分隔线-->                                             
<hr color=red>                                                                
<!--显示错误信息的提示语句-->                                                 
                                                                              
<p align=center>                                                              
     <FONT color=red size=5 align=center>                                     
       <b>                                                                    
          &nbsp&nbsp&nbsp&nbsp错误信息提示                                    
       </b>                                                                   
     </FONT>                                                                  
</p>                                                                          
                                                                              
<!--显示具体的错误-->                                                         
<p align=center>                                                              
      <FONT color=green size=5 align=center>                                  
         <b>                                                                  
            &nbsp&nbsp<?echo"$error"?>                                        
         </b>                                                                 
      </FONT>                                                                 
</p>                                                                          
                                                                              
<!--显示返回的按钮-->                                                         
<div align=center>                                                            
      <a href="JavaScript:history.back()"><image src="images/clickme.gif"></a>
</div>                                                                        
                                                                              
</BODY>                                                                       
</HTML>                   
4. login_ok.php     
<?                                                                          
  include "header.inc.php";                                                 
?>                                                                          
<!--HTML的头定义-->                                                         
<HTML>                                                                      
<HEAD>                                                                      
   <META http-equiv="Content-Type" content="text/html; charset=gb2312">     
</HEAD>                                                                     
                                                                            
<BODY>                                                                      
<!--滚动显示提示信息-->                                                     
<marquee scrolldelay="165" class=myYellow bgcolor=green>                    
  欢迎光临金风社区&nbsp&nbsp&nbsp&nbsp&nbsp                                 
  这是我们的PHP乐园&nbsp&nbsp&nbsp&nbsp&nbsp                                
  希望您能喜欢它~&nbsp&nbsp&nbsp&nbsp&nbsp                                 
</marquee>                                                                  
<!--显示一面迎风飘扬的旗帜作为欢迎信息-->                                   
<img src="images/flag.gif" align=left>                                      
<!--显示本页面的大标题-->                                                   
<h2 align=center color=red>                                                 
   金风社区欢迎您!                                                         
</h2>                                                                       
<!--显示一条红色的水平的分隔线-->                                           
<hr color=red>                                                              
<!--显示欢迎信息-->                                                         
<p align=center>                                                            
  <FONT color=red size=5 align=center>                                      
   <b>                                                                      
     &nbsp&nbsp&nbsp&nbsp您已经成功了!恭喜恭喜                             
   </b>                                                                     
  </FONT>                                                                   
</p>                                                                        
<!--显示欢迎信息-->                                                         
<p align=center>                                                            
  <FONT color=red size=5 align=center>                                      
   <b>                                                                      
     <?echo"您的标识号是".$id ?>                                            
   </b>                                                                     
  </FONT>                                                                   
</p>                                                                        
<!--提示用户继续进行选择-->                                                 
<p align=center>                                                            
   <FONT color=red size=5 align=center>                                     
      <b>                                                                   
        &nbsp&nbsp请选择继续或者退回                                        
      </b>                                                                  
   </FONT>                                                                  
</p>                                                                        
<!--对最下面的按钮进行说明-->                                               
<p align=center>                                                            
    <FONT color=green size=4>                                               
      <b>                                                                   
        &nbsp&nbsp选择左边的按钮继续登记                                    
      </b>                                                                  
    </FONT>                                                                 
    <FONT color=green size=4>                                               
      <b>                                                                   
        &nbsp&nbsp选择右边的按钮退回到主界面                                
      </b>                                                                  
    </FONT>                                                                 
</p>                                                                        
<!--显示两个动态的按钮-->                                                   
<div align=center>                                                          
      <a href="login.php"><image src="images/continue.gif" align=center></a>
      <a href="mainform.php"><image src="images/back.gif"align=center></a>  
</div>                                                                      
</BODY>                                                                     
</HTML>  








本文转自 牛海彬 51CTO博客,原文链接:http://blog.51cto.com/newhappy/76898,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
PHP
php实现数字格式化,数字每三位加逗号的功能函数169856420=&gt;169,856,420
php实现数字格式化,数字每三位加逗号的功能函数169856420=&gt;169,856,420
190 0
|
PHP
PHP实现Workerman实例 高性能PHP Socket即时通讯框架
PHP实现Workerman实例 高性能PHP Socket即时通讯框架
374 0
|
消息中间件 PHP Windows
PHP实现php-amqplib/php-amqplib实例RabbitMq
PHP实现php-amqplib/php-amqplib实例RabbitMq
150 0
|
XML 移动开发 JSON
PHP使用yansongda/pay实现支付宝和微信的支付
PHP使用yansongda/pay实现支付宝和微信的支付
910 0
|
NoSQL PHP Redis
PHP结合redis实现点赞功能
PHP结合redis实现点赞功能
115 0
|
消息中间件 缓存 JSON
PHP实现think-queue介绍
PHP实现think-queue介绍
344 0
|
PHP
php实现定时任务hellogerard/jobby
php实现定时任务hellogerard/jobby
120 0
|
PHP
PHP实现JWT lcobucci/jwt生成jwt token
PHP实现JWT lcobucci/jwt生成jwt token
476 0
|
NoSQL PHP 调度
PHP实现定时任务hellogerard/jobby实例
PHP实现定时任务hellogerard/jobby实例
114 0
|
PHP
PHP实现极光推送jpush/jpush 手机APP消息推送
PHP实现极光推送jpush/jpush 手机APP消息推送
320 0