php會話控制例題:留言板

來源:互聯網
上載者:User

標籤:htm   內容   ati   eve   span   order   require   button   登陸   

資料庫用到的三張表

 

 

 

一.登入介面 (denglu.php   login.php)

 

1.denglu.php

 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7  8 <body> 9 <h1>開發部內部留言板</h1>10 <form action="login.php" method="post">11 <div>使用者名稱:<input type="text" name="UserName" /></div>12 <div>口令:<input type="password" name="PassWord" /></div>13 <input type="submit" value="登入" />14 <a href="denglu.php" style="text-decoration:none"><input type="button" value="複位" /></a>15 </form>16 </body>17 </html>

2.login.php

 1 <?php 2 session_start(); 3 $UserName = $_POST["UserName"]; 4 $PassWord = $_POST["PassWord"]; 5  6 require "DBDA.class1.php"; 7 $db = new DBDA(); 8 $sql = "select PassWord from yuangong where UserName = ‘{$UserName}‘"; 9 $arr = $db->query($sql);10 11 if(count($arr))12 {13     if($arr[0][0] == $PassWord && !empty($PassWord))14     {15         //儲存使用者名稱16         $_SESSION["UserName"] = $UserName;17         18         header("location:main.php");19     }20 }21 else22 {23     header("location:denglu.php");24 }

 

二.主介面 (main.php   tuichu.php)

 

 

1.main.php

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>無標題文檔</title> 6 </head> 7  8 <body> 9 <?php10 session_start();11     12 //    防止繞過登陸直接進入主介面13 if(empty($_SESSION["UserName"]))14 {15     header("location:denglu.php");16     exit;17 }18     19 require "DBDA.class1.php";20 $db = new DBDA();21 $UserName = $_SESSION["UserName"];22 ?>23 <div>24 <a href="fabu.php">發布資訊</a>25 <a href="tuichu.php">退出系統</a>26 </div><br /><br />27 <h1>留言資訊:</h1>28 <table width="100%" border="1" >29     <tr>30         <td>發送人</td>31         <td>發送時間</td>32         <td>接收人</td>33         <td>資訊內容</td>34     </tr>35       <?php36     37     //顯示接收者是我的,或者是所有人的38     $sql = "select * from liuyan where Recever=‘{$UserName}‘ or Recever=‘suoyou‘";39     $arr = $db->query($sql);40     foreach($arr as $v)41     {42     43          echo "<tr>44                    <td>{$v[1]}</td>45                 <td>{$v[3]}</td>46                 <td>{$v[2]}</td>47                 <td>{$v[4]}</td>48                </tr>";49     }50     51     ?>    52 53 </table>54 </body>55 </html>

2.tuichu.php

1 <?php2 3 session_start();4 5 unset($_SESSION["UserName"]);6 7 header("location:denglu.php");

 

三.發送頁面 (fabu.php   fabuchuli.php)

 

1.fabu.php

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>無標題文檔</title> 6 </head> 7  8 <body> 9 <div>10 <a href="main.php">查看資訊</a>11 <a href="tuichu.php">退出系統</a>12 </div>13 <h1>資訊發送:</h1>14 <form action="fabuchuli.php" method="post">15 <div>接收人:16 <select name="jsr">17     <option value="suoyou">所有人</option>18     <?php19     session_start();20     $UserName = $_SESSION["UserName"];21     require"DBDA.class1.php";22     $db = new DBDA();23     //方法一24     $sql = "select friend.Friend,yuangong.Name from friend,yuangong where friend.Friend = yuangong.UserName and friend.Me = ‘{$UserName}‘";25     $arr = $db->query($sql);26         27     foreach($arr as $v)28     {29         echo "<option value=‘{$v[0]}‘>{$v[1]}</option>";30     }31     //方法二32     /*$sql = "select Friend from friend where Me =‘{$UserName}‘";33     $arr = $db->query($sql);34     foreach($arr as $v)35         {36             $v[0];37             $sname = "select Name from yuangong where UserName = ‘{$v[0]}‘";38             $aname = $db->query($sname);39             echo"<option value=‘{$v[0]}‘>{$aname[0][0]}</option>";40         }*/41     ?>                42 </select></div>43 <div>資訊內容:<textarea name="neirong"></textarea></div>44 <input type="submit" value="發送" />45 <a href="fabu.php" style="text-decoration:none"><input type="button" value="複位" /></a>46 </form>47 </body>48 </html>

2.fabuchuli.php

 1 <?php 2 session_start(); 3 $UserName = $_SESSION["UserName"]; 4 $jsr = $_POST["jsr"]; 5 $nr = $_POST["neirong"]; 6 $Times = date("Y-m-d  H:i:s"); 7  8  9 require"DBDA.class.php";10 $db = new DBDA();11 $sql = "insert into liuyan values(‘‘,‘{$UserName}‘,‘{$jsr}‘,‘{$Times}‘,‘{$nr}‘)";12 $db->query($sql,0);13 header("location:fabu.php");

 

php會話控制例題:留言板

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.