《PHP編程:php實現(xiàn)留言板功能(會話控制)》要點:
本文介紹了PHP編程:php實現(xiàn)留言板功能(會話控制),希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP編程本文實例為大家分享了php留言板功能的具體代碼,供大家參考,具體內(nèi)容如下
PHP編程數(shù)據(jù)庫用到的三張表
PHP編程
PHP編程
PHP編程
PHP編程一.登錄界面 (denglu.php?? login.php)
PHP編程
PHP編程1.denglu.php
PHP編程
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>開發(fā)部內(nèi)部留言板</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="復(fù)位" /></a>
</form>
</body>
</html>
PHP編程2.login.php
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");
}
PHP編程二.主界面(main.php?? tuichu.php)
PHP編程
PHP編程1.main.php
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>無標(biāo)題文檔</title>
</head>
<body>
<?php
session_start();
// 防止繞過登陸直接進(jìn)入主界面
if(empty($_SESSION["UserName"]))
{
header("location:denglu.php");
exit;
}
require "DBDA.class1.php";
$db = new DBDA();
$UserName = $_SESSION["UserName"];
?>
<div>
<a href="fabu.php">發(fā)布信息</a>
<a href="tuichu.php">退出系統(tǒng)</a>
</div><br /><br />
<h1>留言信息:</h1>
<table width="100%" border="1" >
<tr>
<td>發(fā)送人</td>
<td>發(fā)送時間</td>
<td>接收人</td>
<td>信息內(nèi)容</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>
PHP編程2.tuichu.php
PHP編程
<?php
session_start();
unset($_SESSION["UserName"]);
header("location:denglu.php");
PHP編程三.發(fā)送頁面(fabu.php?? fabuchuli.php)
PHP編程
PHP編程1.fabu.php
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>無標(biāo)題文檔</title>
</head>
<body>
<div>
<a href="main.php">查看信息</a>
<a href="tuichu.php">退出系統(tǒng)</a>
</div>
<h1>信息發(fā)送:</h1>
<form action="fabuchuli.php" method="post">
<div>接收人:
<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></div>
<div>信息內(nèi)容:<textarea name="neirong"></textarea></div>
<input type="submit" value="發(fā)送" />
<a href="fabu.php" style="text-decoration:none"><input type="button" value="復(fù)位" /></a>
</form>
</body>
</html>
PHP編程2.fabuchuli.php
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編程以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持維易PHP.
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/754.html