具体内容如下
数据库用到的三张表
一.登录界面 (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
<?php session_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> <?php session_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
<?php session_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
<?php session_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");
相关推荐:
简单实现php留言板功能
php开发留言板的增,删,改,查操作
php实现留言板功能(会话控制)
以上就是php基于会话控制实现留言板功能的详细内容。