本文实例为大家分享了php留言板功能的具体代码,供大家参考,具体内容如下

数据库用到的三张表

php实现留言板功能(会话控制)

php实现留言板功能(会话控制)

php实现留言板功能(会话控制)

一.登录界面 (denglu.php   login.php)

php实现留言板功能(会话控制)

1.denglu.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>

<body>
<h1>开发部内部留言板</h1>
<form action="login.php" method="post">
<div>用户名:<input type="text" name="UserName" /></div>
<div>口令:<input type="password" name="PassWord" /></div>
<input type="submit" value="登录" />
<a href="denglu.php" style="text-decoration:none"><input type="button" value="复位" /></a>
</form>
</body>
</html>

2.login.php

<"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)

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>
<"UserName"]))
{
  header("location:denglu.php");
  exit;
}
  
require "DBDA.class1.php";
$db = new DBDA();
$UserName = $_SESSION["UserName"];
"fabu.php">发布信息</a>
<a href="tuichu.php">退出系统</a>
</div><br /><br />
<h1>留言信息:</h1>
<table width="100%" border="1" >
  <tr>
    <td>发送人</td>
    <td>发送时间</td>
    <td>接收人</td>
    <td>信息内容</td>
  </tr>
   <"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>";
  }
  
  "htmlcode">
<"UserName"]);
header("location:denglu.php"); 

三.发送页面(fabu.php   fabuchuli.php)

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>
<div>
<a href="main.php">查看信息</a>
<a href="tuichu.php">退出系统</a>
</div>
<h1>信息发送:</h1>
<form action="fabuchuli.php" method="post">
<div>接收人:
<select name="jsr">
  <option value="suoyou">所有人</option>
  <"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>";
    }*/
  "neirong"></textarea></div>
<input type="submit" value="发送" />
<a href="fabu.php" style="text-decoration:none"><input type="button" value="复位" /></a>
</form>
</body>
</html>

2.fabuchuli.php

<"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");

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
php,留言板

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com

评论“php实现留言板功能(会话控制)”

暂无“php实现留言板功能(会话控制)”评论...