第3週-開始設計開發首頁相關程式 請開啟檔案檢視ep.cust.edu.tw/c.pdf epconfig.php <?php $host = "127.0.0.1"; $user = "root"; $pwd = "1234"; $dbname="myep"; $conn=mysqli_connect($host,$user,$pwd) or die("無法連接主機"); mysqli_query($conn,'SET NAMES utf8'); mysqli_select_db($conn,$dbname) or die("無法連接資料庫"); $adminuser="1111111111"; // 自行設定管理者帳號 $adminpass="1111111111"; // 自行設定管理者密碼 ?> index.php <?php echo "<FRAMESET rows='25%,*'> <FRAME name='top' SRC='logo.jpg' scrolling=no> <FRAMESET cols='20%,*' > <FRAME name='left' SRC='eplogin.php'> <FRAME name='middle' SRC='epnews.php'> </FRAMESET> </FRAMESET>"; ?> eplogin.php <?php include "epconfig.php"; $command=$_POST["command"];
if ($command=="") { echo "<html><head><title>學生學習歷程網登入頁面</title> <link rel='stylesheet' type='text/css' href='style.css'> </head><body><center> <form method=post action=''> <fieldset> <span style='background-color: #ccccff'>帳號:</span> <input type=text name=username size=8 /><br> <span style='background-color: #ccccff'>密碼:</span> <input type=password name=password size=8><br> <input class='cmd' type=submit name=command value='登入'> </form></fieldset>"; $pglist=array("epnews.php","epstat.php","eplist.php"); $namelist=array("最新消息檢視","各班網站統計","各班網站列表"); foreach ($pglist as $key => $pg) { $name=$namelist[$key]; echo "<tr><form method='post' action='$pg' target='middle' ><td> <input class='cmd1' type='submit' name='command' value='$name'> </td></form></tr>"; } echo "</table></center></body></html>"; }
if ($command=='登入') { $username=trim($_POST["username"]); $password=trim($_POST["password"]); if ($username==$adminuser && $password==$adminpass) $ident="1"; // 管理者 else { $sql="select * from epstmd where student_no='$username' and password='$password'"; $result=mysqli_query($conn,$sql); $no_of_rows=mysqli_num_rows($result);
if ($no_of_rows>0) $ident="2"; else { echo "登入失敗,請回前頁重新登入"; die(); } } if ($ident=="1") { // 系統管理者管理介面 } if ($ident=="2") { // 學生端管理介面 } }
完成上述程式, 並以管理者與學生身分登入,能夠正確的顯示介面 再將 <FRAME name='top' SRC='logo.jpg' scrolling=no>改成 <FRAME name='top' SRC='top.php' scrolling=no> 利用top.php可以改變系統程式畫面的網頭 例如單數日一種網頭 雙數日一種網頭 訪客介面 epnews.php,epstat.php,eplist.php 最新消息檢視,各班網站統計,各班網站列表
系統管理介面 epclass.php,epstmd.php,epheader.php,eppost.php 班級代碼資料,學生基本資料,上傳網頭資料,發布最新消息
使用者介面 epcreate.php,eplink.php,epchange.php; 建立個人網站,發表文章內容,更改基本資料