php基於會話控制實現留言板功能

來源:互聯網
上載者:User
這篇文章主要為大家詳細介紹了php實現留言板功能,會話控制的案例,具有一定的參考價值,感興趣的小夥伴們可以參考一下

具體內容如下

資料庫用到的三張表

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

1.denglu.php

<!DOCTYPE html><html><head><meta charset="UTF-8"><title></title></head><body><h1>開發部內部留言板</h1><form action="login.php" method="post"><p>使用者名稱:<input type="text" name="UserName" /></p><p>口令:<input type="password" name="PassWord" /></p><input type="submit" value="登入" /><a href="denglu.php" style="text-decoration:none"><input type="button" value="複位" /></a></form></body></html>

2.login.php

<?phpsession_start();$UserName = $_POST["UserName"];$PassWord = $_POST["PassWord"];require "DBDA.class1.php";$db = new DBDA();$sql = "select PassWord from yuangong where UserName = '{$UserName}'";$arr = $db->query($sql);if(count($arr)){  if($arr[0][0] == $PassWord && !empty($PassWord))  {    //儲存使用者名稱    $_SESSION["UserName"] = $UserName;        header("location:main.php");  }}else{  header("location:denglu.php");}

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

1.main.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title></head><body><?phpsession_start();  //  防止繞過登陸直接進入主介面if(empty($_SESSION["UserName"])){  header("location:denglu.php");  exit;}  require "DBDA.class1.php";$db = new DBDA();$UserName = $_SESSION["UserName"];?><p><a href="fabu.php">發布資訊</a><a href="tuichu.php">退出系統</a></p><br /><br /><h1>留言資訊:</h1><table width="100%" border="1" >  <tr>    <td>發送人</td>    <td>發送時間</td>    <td>接收人</td>    <td>資訊內容</td>  </tr>   <?php    //顯示接收者是我的,或者是所有人的  $sql = "select * from liuyan where Recever='{$UserName}' or Recever='suoyou'";  $arr = $db->query($sql);  foreach($arr as $v)  {       echo "<tr>          <td>{$v[1]}</td>        <td>{$v[3]}</td>        <td>{$v[2]}</td>        <td>{$v[4]}</td>        </tr>";  }    ?>  </table></body></html>

2.tuichu.php

<?phpsession_start();unset($_SESSION["UserName"]);header("location:denglu.php");

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

1.fabu.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title></head><body><p><a href="main.php">查看資訊</a><a href="tuichu.php">退出系統</a></p><h1>資訊發送:</h1><form action="fabuchuli.php" method="post"><p>接收人:<select name="jsr">  <option value="suoyou">所有人</option>  <?php  session_start();  $UserName = $_SESSION["UserName"];  require"DBDA.class1.php";  $db = new DBDA();  //方法一  $sql = "select friend.Friend,yuangong.Name from friend,yuangong where friend.Friend = yuangong.UserName and friend.Me = '{$UserName}'";  $arr = $db->query($sql);      foreach($arr as $v)  {    echo "<option value='{$v[0]}'>{$v[1]}</option>";  }  //方法二  /*$sql = "select Friend from friend where Me ='{$UserName}'";  $arr = $db->query($sql);  foreach($arr as $v)    {      $v[0];      $sname = "select Name from yuangong where UserName = '{$v[0]}'";      $aname = $db->query($sname);      echo"<option value='{$v[0]}'>{$aname[0][0]}</option>";    }*/  ?>        </select></p><p>資訊內容:<textarea name="neirong"></textarea></p><input type="submit" value="發送" /><a href="fabu.php" style="text-decoration:none"><input type="button" value="複位" /></a></form></body></html>

2.fabuchuli.php

<?phpsession_start();$UserName = $_SESSION["UserName"];$jsr = $_POST["jsr"];$nr = $_POST["neirong"];$Times = date("Y-m-d H:i:s");require"DBDA.class.php";$db = new DBDA();$sql = "insert into liuyan values('','{$UserName}','{$jsr}','{$Times}','{$nr}')";$db->query($sql,0);header("location:fabu.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.