社区源代码(php&mysql)之一
以下为sql.inc.php文件
  <?
$link
=mysql_pconnect("localhost","userid","password")or die(mysql_error());
$link1=mysql_select_db("table")or die(mysql_error());
?>

以下为header.inc文件
<?
   header
("Cache-Control: no-cache, must-revalidate");
   
header("Pragma: no-cache");
?>


以下为index.php文件
<?
 
include "inc/sql.inc.php" 
 include 
"inc/header.inc";
 
  function 
addonline(){                                     //添加在线信息
      
global $userid,$password,$REMOTE_ADDR,$id,$login_ip;
      
$id=time();
      
$old_time=time();
      
$login_ip=$REMOTE_ADDR;

      
$SQL="DELETE FROM online WHERE userid='$userid'";      //删除信息
       
mysql_query($SQL) or die(mysql_error());

      
$SQL="INSERT INTO online (id,userid,login_ip,old_time) VALUES  ('$id','$userid','$login_ip','$old_time')";             //插入用户信息
      
mysql_query($SQL) or die(mysql_error());
  }
    
  if(
$ok){
     if(empty(
$userid)||empty($password)){
         
$error=1;
         
header("Location:error.php?error=$error");
     }

     else{
            
$sql="select * from user where userid='$userid'";
            
$result=mysql_query($sql) or die(mysql_error());
            
$row=mysql_fetch_array($result);
         
           if(isset(
$row["userid"])){          //判断此用户名是否存在
             
if($password==$row["password"]){
                 
                 
$sql="select * from user_attr where userid='$userid'";  //更新信息
                 
$result=mysql_query($sql) or die(mysql_error());
                 
$row=mysql_fetch_array($result) or die(mysql_error());

                 
$counts=$row["counts"];
                 
$exper_cent=$row["exper_cent"];
                 
$money=$row["money"];

                 
$counts++;
                 
$exper_cent+=5;
                 
$money+=10;
                 
$login_ip=$REMOTE_ADDR;

                 if(
$exper_cent>=100$level=1;
                 if(
$exper_cent>=300$level=2;
                 if(
$exper_cent>=600$level=3;
                 if(
$exper_cent>=1000$level=4;
                 if(
$exper_cent>=1500$level=5;
                 if(
$exper_cent>=2000$level=6;


                 
$sql="UPDATE user_attr SET       counts='$counts',exper_cent='$exper_cent',money='$money',level='$level',last_ip='$login_ip' WHERE userid='$userid'";
                 
$result=mysql_query($sql);

                 
addonline();
                 
header("Location:club/club.php?id=$id");
             }
             else{
                 
$error=2;
                 
header("Location:error.php?error=$error");
             }
           }
            else{                    
//此用户名不存在则添加用户信息
                
$sql="insert into user (userid,password) values ('$userid','$password')";
                
mysql_query($sql) or die(mysql_error());
                
                
$level=1;
                
$counts=1;
                
$exper_cent=100;
                
$money=200;
                
$login_ip=$REMOTE_ADDR;

                
$sql="insert into user_attr (counts,exper_cent,money,userid,level,last_ip) values ('$counts','$exper_cent','$money','$userid','$level','$login_ip')";
                
mysql_query($sql) or die(mysql_error());
                
                
addonline();
                
header("Location:club/club.php?id=$id\n");
            }
        }
  }

     
$sql="select * from bbs order by read_value DESC";
     
$result=mysql_query($sql);
     
$sqls="select * from bbs order by signature DESC";
     
$results=mysql_query($sqls);

     for(
$i=0;$i<6;$i++){
         
$row=mysql_fetch_array($result);
           
$read_value[$i]=$row[read_value];
           
$title[$i]=$row[title];
           
$writer[$i]=$row[writer];
           
$bbsid[$i]=$row[bbsid];

        
$rows=mysql_fetch_array($results);
           
$read_values[$i]=$rows[read_value];
           
$titles[$i]=$rows[title];
           
$writers[$i]=$rows[writer];
           
$bbsids[$i]=$rows[bbsid];
     }

     function 
printhot(){
         global 
$read_value,$title,$writer,$bbsid;
         global 
$read_values,$titles,$writers,$bbsids;

      for(
$i=0;$i<6;$i++){
      echo 
"<tr bgcolor=#00FFFF>";
      echo 
"<td valign=center height=30 align=center width=42>".$read_value[$i]."</td>";
      echo 
"<td valign=center height=30 align=center width=169><a href=club/article.php?bbsid=$bbsid[$i] target=_self>".$title[$i]."</a></td>";
      echo 
"<td valign=center height=30 align=center width=73><a href=club/look.php?writer=$writer[$i] target=_self>".$writer[$i]."</a></td>";
      echo 
"<td valign=center align=center width=44>".$read_values[$i]."</td>";
      echo 
"<td valign=center align=center width=172><a href=club/article.php?bbsid=$bbsids[$i] target=_self>".$titles[$i]."</a></td>";
      echo 
"<td valign=center align=center width=78><a href=club/look.php?writer=$writers[$i] target=_self>".$writers[$i]."</a></td>";
      echo 
"</tr>";
      }
     }
?>

<html>
<head>
<title>EFLYING</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="css/cright.css" rel=stylesheet>
<script language="JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0">

<div id="Layer1" style="position:absolute; left:10; top:10; width:698px; height:77px; z-index:1; background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px none #000000"> 
  <table width="100%" border="0" cellspacing="0" cellpadding="0" height="70" align="center">
    <tr> 
      <td width="119" height="70" valign="top">&nbsp;&nbsp;&nbsp;&nbsp; 
        <div align="center"></div>
      </td>
      <td width="579"> 
        <div align="center"><img src="image/banner4.gif" width="468" height="60"></div>
      </td>
    </tr>
  </table>
</div>

  <div id="layer2" style="position:absolute; left:10px;top:85px; z-index:1; width:760px; height:360px"> 
  <CENTER>
    <table cellspacing=0 cellpadding=0 width="100%" height="100%" border=1 bgcolor=#ffffff bordercolordark=#33ccff bordercolorlight=#0f1f3f>
      <TBODY> 
      <TR> 
        <TD> 
          <table cellspacing=0 cellpadding=0 width="100%" HEIGHT="8%" border=1 bgcolor=#00CCFF bordercolordark=#0f1f3f bordercolorlight=#33ccff>
            <TR> 
              <TD> </TD>
            </TR>
          </TABLE>
          </TD> </TR>
      </TBODY> 
    </TABLE></center></div>

<div id="Layer3" style="position:absolute; left:30px; top:85px; z-index:1; width: 212px; height: 33px"> 
  <table border="0" cellSpacing=0 cellPadding=0 height="33">
      <tr>
        <td>
         <MARQUEE scrollDelay=180 width=150 
                  height=12><font size="2" color=#ffff00>[请注意您进入社区不需要注册]</font></MARQUEE>
        </td>
      </tr>
     </table>
 </div>
<div id="Layer4" style="position:absolute; left:220px; top:85px; z-index:1; width: 456px; height: 52px"> 
  <form name="form1" action="<?echo $PHP_SELF?>" method=post>
    <table border="0" cellSpacing=0 cellPadding=0 height="33">
      <tr> 
        <td width="50" border="0"> <font color="#0000ff" size="2">用户名:</font> 
        <td border="0"> 
          <input type="text" name="userid" size="16" maxlength="16" value="" class=textborder    onMouseover="this.focus();return true">
        <td width="40" align="center" border="0"> <font color="#0000ff" size="2">密码:</font> 
        <td border="0"> 
          <input type="password" name="password" size="16" maxlength="16" class=textborder            onMouseover="this.focus();return true">
        <td width="50" align="center" border="0">
          <input type="submit" name="ok" value="登陆" style="background-color:3366FF;color:FFFFFF;border: 1 double" onMouseover="this.style.color='#abe8fe'" onMouseout="this.style.color='#ffffff'">
        </td>
        <td width="50" align="center" border="0">&nbsp;</td>
      </tr>
    </table>
  </form></div>
<div id="Layer5" style="position:absolute; left:580px; top:84px; z-index:1; width: 180px; height: 33px"> 
  <table border="0" cellSpacing=0 cellPadding=0 height="33">
      <tr>
        <td>
         <MARQUEE scrollDelay=180 width=150 
                  height=12><font size="2" color=#ffff00>[请记住您的用户名和密码]</font></MARQUEE>
        </td>
      </tr>
     </table>
 </div>
 <div id="Layer6" style="position:absolute; left:664px; top:8px; width:80px; height:99px; z-index:5">
    <img src="image/k0103.gif" width="89" height="135">
 </div>
<div id="Layer7" style="position:absolute; left:10px; top:11px; width:129px; height:74px; z-index:3">
   <img src="image/eflying.jpg" width="130" height="63">
</div>
<div id="Layer8" style="position:absolute; left:10px; top:115px; width:129px; height:328px; z-index:3">
<table cellspacing=0 cellpadding=0 width="100%" height="100%" border=1 bgcolor=#00ccff bordercolordark=#0f1f3f bordercolorlight=#33ccff>
      <TBODY> 
      <TR> 
        <TD bgcolor=#00CCFF>&nbsp;</TD>
      </TR>
      </TBODY>
</table>
</div>
<div id="Layer9" style="position:absolute; left:12px; top:112px; width:126px; height:5px; background-color:#00ccff;z-index:4">
</div>
<div id="Layer10" style="position:absolute; left:149px; top:125px; width:609px; height:1px;z-index:4"> 
  <table width="610" border="1" cellspacing="0" cellpadding="0" height="100%" bordercolordark="#ffffff" bordercolorlight="#000000">
    <tr> 
      <td height="32" valign="center" align="center" colspan="3" bgcolor="#00CCFF"><FONT SIZE="3" COLOR="#ffff00">【TOP文章】</FONT></td>
      <td width="16" rowspan="8" valign="center" align="center">社区经典部分</td>
      <td valign="center" align="center" colspan="3" bgcolor="#00CCFF"><FONT SIZE="3" COLOR="#ffff00">【精华篇】</FONT></td>
    </tr>
    <tr bgcolor="#00FFFF"> 
      <td valign="center" height="30" align="center" width="42">点击数</td>
      <td valign="center" height="30" align="center" width="169">文章标题</td>
      <td valign="center" height="30" align="center" width="73">作者</td>
      <td valign="center" align="center" width="44">点击数</td>
      <td valign="center" align="center" width="172">文章标题</td>
      <td valign="center" align="center" width="78">作者</td>
    </tr>
    <? printhot();?>
  </table>
</div>
<div id="Layer11" style="position:absolute; left:149px; top:393px; width:609px; height:50px;z-index:4">
<?
include "inc/copyright.inc";
?>
</div>
</body>
</html>