PHP之密碼加密的幾種方式
711
2023-12-10
PHP實現留言板功能:
1 首先是登錄頁面:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>留言板登錄</title> <script src="http://www.gimoo.net/t/1712/bootstrap/js/jquery-1.11.2.min.js"></script> <script src="http://www.gimoo.net/t/1712/bootstrap/js/bootstrap.min.js"></script> <link rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css"/> </head> <style> .header{ margin-left: 550px; margin-top: 150px; height: 300px; max-width: 300px; } .xiugai{ max-width: 200px; } .login{ margin-top: 10px; } </style> <body> <form action="messloginchuli.php" method="post"> <div class="header"> <h2>開發部內部留言板</h2> <div class="input-group xiugai"> <span class="input-group-addon" >用戶名:</span> <input type="text" class="form-control" name="uid" placeholder="請輸入用戶名"> </div> <div class="input-group xiugai" > <span class="input-group-addon">口令:</span> <input type="text" class="form-control" name="pwd" placeholder="請輸入口令"> </div> <button type="submit" class="btn btn-success login">登錄</button> </div> </form> </body> </html>
2 登錄頁面完成后要進入登錄處理頁面了,也就是上面提交到的messloginchuli.php
<?php session_start(); // 登錄之后要把所包含登錄的頁面連接起來,開啟session $uid = $_POST["uid"]; $pwd = $_POST["pwd"]; require_once "./DBDA.class.php"; $db = new DBDA(); $sql = "select password from yuangong where username='{$uid}'"; $arr = $db->query($sql,0); //var_dump($arr[0][0]); if($arr[0][0]=$pwd && !empty($pwd)){ $_SESSION["uid"]=$uid; header("location:message.php"); } ?>
登錄頁面效果如圖:
3.登錄完成后是進入主頁面,也就是顯示自己收到的對話內容,下面是設計的數據庫的表格和主頁面的代碼:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="http://www.gimoo.net/t/1712/bootstrap/js/jquery-1.11.2.min.js"></script> <script src="http://www.gimoo.net/t/1712/bootstrap/js/bootstrap.min.js"></script> <link rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css"/> </head> <style> .mess{ max-width: 800px; margin-left: 250px; margin-top: 150px; } </style> <body> <?php session_start(); $uid = $_SESSION["uid"]; if(empty($_SESSION["uid"])){ header("location:messlogin.php"); exit; } ?> <div > <a rel="external nofollow" >發布信息</a> <a rel="external nofollow" >退出系統</a> </div> <table class="table table-bordered mess" > <caption > 留言信息: </caption> <thead> <tr> <th>發送人</th> <th>發送時間</th> <th>接收人</th> <th>信息內容</th> </tr> </thead> <tbody> <?php require_once "./DBDA.class.php"; $db = new DBDA(); $sql = "select * from liuyan where recever='{$uid}' or recever='all'"; $arr = $db->query($sql,0); foreach($arr as $v){ echo "<tr> <td>{$v[1]}</td> <td>{$v[2]}</td> <td>{$v[3]}</td> <td>{$v[4]}</td> </tr>"; } ?> </tbody> </table> </body> </html>
退出登錄系統實現用戶注銷,返回登錄頁面功能代碼如下:
<?php session_start(); $uid = $_SESSION["uid"]; unset($uid); header("location:messlogin.php"); ?>
代碼寫到這里,比較重要的部分就完成了,下面是要進入發布信息頁面了,相當于之前寫的添加的頁面,其處理頁面也是和之前沒什么區別的,差別在于現在的處理頁面是在用戶登錄的情況下操作的,需要用session把所有的登錄情況下的頁面連接起來
主頁面效果如圖:
4.最后是信息發布頁面,可以給任何人發送信息
代碼如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>發布信息界面</title> <script src="http://www.gimoo.net/t/1712/bootstrap/js/jquery-1.11.2.min.js"></script> <script src="http://www.gimoo.net/t/1712/bootstrap/js/bootstrap.min.js"></script> <link rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css"/> </head> <style> .mess{ max-width: 200px; margin-top: 10px; } .mess1{ margin-top: 10px; } .opt{ max-width: 200px; margin-left: 80px; } .txt{ max-width: 200px; } </style> <body> <?php session_start(); $uid = $_SESSION["uid"]; if (empty($_SESSION["uid"])) { header("location:messlogin.php"); exit ; } ?> <div > <div > <a rel="external nofollow" >查看信息</a> <a rel="external nofollow" >查看發送信息</a> </div> <form class="form-horizontal" role="form" action="infochuli.php" method="post"> <div class="form-group"> <label for="firstname" class="col-sm-2 control-label mess1">接收人:</label> <div class="form-group "> <select class="form-control opt" name="recever"> <option value="all">所有人</option> <?php require_once "./DBDA.class.php"; $db = new DBDA(); //這里可以給特定的朋友發送信息的sql語句 //$sql = "select firend.firend,yuangong.name from firend,yuangong where firend.firend //= yuangong.username and firend.me = '{$uid}'"; $sname = "select * from yuangong where username not in ('{$uid}')"; $arr = $db->query($sname,0); //var_dump($arr[0][2]); foreach($arr as $v){ echo "<option value='{$v[0]}'>{$v[2]}</option>"; } ?> </select> </div> </div> <div class="form-group"> <label for="lastname" class="col-sm-2 control-label mess1">信息內容:</label> <div class="col-sm-10"> <textarea class="form-control txt" rows="3" name="content"></textarea> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default"> 發送 </button> </div> </div> </form> </div> </body> </html>
發信息頁面如圖:
5.發布信息完成后要進入處理頁面了,也就是提交到的infochuli.php,最后返回發送信息界面
<?php session_start(); $uid = $_SESSION["uid"]; $recever = $_POST["recever"]; $content = $_POST["content"]; $arr = $_POST["recever"]; $t = date("Y-m-d H:i:s"); require_once "./DBDA.class.php"; $db = new DBDA(); $sql = "insert into liuyan values('','{$uid}','{$t}','{$recever}','{$content}',0)"; $arr = $db->query($sql); if($arr && !empty($arr)){ header("location:publish_info.php"); }else{ echo "發送失敗!"; } ?>
以上這篇使用PHP連接數據庫實現留言板功能的實例講解(推薦)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持綠夏網。
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!