5.26练习题简单留言板
功能流程
- 登陆功能(非内部人员不登录无法查看)
- 发布功能
- 查看功能(其中查看功能又分为指定人员查看和所有人都能查看,可以在发布信息时自定义设置)
- 退出功能
效果如下:
代码如下:
主界面:
<!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['uid'])) { header("location:login.php"); exit; } $uid = $_SESSION['uid']; ?> <div><h2>Hello <?php if(!empty($_SESSION['uid'])){echo $_SESSION['uid'];} ?></h2><a href="fabu.php">发布信息</a> <a href="exit.php">退出系统</a></div> <table width="1000" border="1" cellpadding="0" cellspacing="0"> <tr><td>发送人</td><td>发送时间</td><td>接收人</td><td>信息内容</td></tr> <?php include ("database.class.php"); $db = new database(); $r = $db->Query("select * from LiuYan where Recever = '{$uid}' or Recever = 'everybody'"); foreach ($r as $v) { $sqlsender = "select Name from Yuangong where UserName = '{$v[1]}'";//发送者姓名 $s1 = $db->str_ajax($sqlsender); $r1 = ""; if($v[2]=="everybody") { $r1 = "所有人"; } else { $sqlr = "select Name from Yuangong where UserName = '{$uid}'"; $r1 = $db->str_ajax($sqlr); } echo "<tr><td>{$s1}</td> <td>{$v[3]}</td> <td>{$r1}</td> <td>{$v[4]}</td></tr>";//发送人、发送时间、接收人、信息内容 } ?> </table> </body> </html>
登陆界面:
<!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> <h1 align="center">登录界面</h1> <form action="logincl.php" method="post"> <div>用户名:<input type="text" name="uid" /></div> <div>口令:<input type="password" name="pwd" /></div> <div><input type="submit" value="登陆" /> <input type="reset" value="复位" /></div> </form> </body> </html>
登陆处理界面:
<?php session_start(); header("Content-Type:text/html;charset=utf-8"); $UserName = $_POST['uid']; $PassWord = $_POST['pwd']; include ("database.class.php"); $db = new database(); $sql = "select count(*) from YuanGong where UserName = '{$UserName}' && PassWord = '{$PassWord}'"; $result = $db->Query($sql); if($result[0][0]==1) { $_SESSION['uid'] = $UserName; echo "正在登陆,页面跳转中~"; echo '<script>setTimeout(\'location="main.php"\',3000)</script>'; } else { echo "用户名、密码不存在"; echo '<script>setTimeout(\'location="login.php"\',3000)</script>'; }
信息发布界面:
<!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['uid'])) { header("location:login.php"); } $uid = $_SESSION['uid']; include ("database.class.php"); $db = new database(); ?> <div><a href="main.php">查看信息</a> <a href="exit.php">退出系统</a></div> <h1>信息发送</h1> <form action="fbcl.php" method="post"> <div>接收人:<select name="receiver" /> <option value="everybody">所有人</option> <?php $sql = "select firend from firend where me ='{$uid}'"; $attr = $db->Query($sql); foreach ($attr as $v) { $sqln = "select Name from YuanGong where UserName = '{$v[0]}'"; $name = $db->str_ajax($sqln); echo "<option value='{$v[0]}'>{$name}</option>"; } ?> </select></div> <div>信息内容:<textarea name="content"></textarea></div> <div><input type="submit" value="发送" /> <input type="reset" value="复位" /></div> </form> </body> </html>
信息发布处理界面:
<?php session_start(); header("Content-Type:text/html;charset=utf-8"); if(!empty($_POST['receiver'])&&!empty($_POST['content'])) { $r = $_POST['receiver']; $c = $_POST['content']; $t = date("Ymdhis",time()); $uid = $_SESSION['uid']; include ("database.class.php"); $db = new database(); $sql = "insert into LiuYan values('','{$uid}','{$r}','{$t}','{$c}',false)"; $result = $db->Query($sql,1); if($result) { header("location:main.php"); } else { echo "发布失败"; } } else { echo "请填写发布信息"; }
退出系统界面:
<!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(); unset($_SESSION['uid']); header("location:login.php"); ?> </body> </html>