//ex8.php <?php session_start();//網頁要記錄有登錄,都是使用 session變數來記錄 if (!isset($_SESSION['auth'])) { header('Location: ex8-login.php'); exit; } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Ex8</title> </head> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <!-- Optional theme --> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css"> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> <body> <ul class="nav nav-pills"> <li role="presentation" class="active"><a href="#">Ex8</a></li> <li role="presentation"><a href="ex8-logout.php">登出</a></li> </ul> <p><img src="title_2.jpg" width="550" height="77" /></p> //ex8-login.php <?php $message ="請輸入密碼"; if(isset($_POST["Submit"])){ $Usename=$_POST["Usename"]; $Password=$_POST["Password"]; if ($Usename == "abc" && $Password =="123") { session_start(); $_SESSION['auth'] = true;//認證成功,設定一個session變數 header('Location: ex8.php'); exit; } else { $message="帳號或密碼錯誤"; } } ?> <h1>Ex8-login</h1> <form action="ex8-login.php" method="post"> <table width="200″ border="1″> <tr> <td>帳號</td> <td><input type="text" name="Usename" ></td> <td><?php echo $message?> </td> </tr> <tr> <td>密碼</td> <td><input type="password" name="Password"></td> <td><input type="submit" name="Submit" value="登入" /></td> </tr> </table> </form> //ex8-logout.php session_start(); unset($_SESSION['auth']); header('Location: ex8-login.php'); exit;
Posts Tagged ‘103(下)’
//ex9.php <?php $db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'phpuser', '23323456'); if (isset($_POST["Submit"])) { //讀入表單參數 $email = $_POST["EMail"]; $message = $_POST["Message"]; $msgdate = date("Y-m-d H:i:s"); //寫入資料庫 $query = "INSERT INTO guestbook(email, message, msgdate) VALUES ('$email','$message','$msgdate')"; $result = $db->exec($query); } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Ex9:Guestbook</title> </head> <body> <h1>Ex9:Guestbook</h1> <form action="ex9.php" method="post"> <table border="1" width="100%"> <tr> <td colspan="2">請問您有何建議</td> </tr> <tr> <td >EMail:</td><td ><input type="text" name="EMail" /></td> </tr> <tr> <td >留言:</td><td ><input type="text" name="Message" /></td> </tr> <tr><td> <input type="submit" name="Submit" value="送出留言" /></td><td></td> </tr> </table> </form> <h1>留言內容</h1> <hr /> <table border="1" width="100%"> <?php $query="SELECT * FROM guestbook ORDER BY msgdate DESC LIMIT 10"; $stmt = $db->prepare($query); $stmt->execute(); while($row = $stmt->fetch()){ print "<tr> <td>".$row["gid"]."</td> <td>".$row["email"]."</td> <td>".$row['message']."</td> <td>".$row['msgdate']."</td> </tr>"; } ?> </table>
25
五月
程式設計二程式 05/25: ex7
//ex7-login.php
<?php
$message=”請輸入密碼”;
if(isset($_POST["Submit"])){
//
$Usename=$_POST["Usename"];
$Password=$_POST["Password"];
if ($Usename == “abc” && $Password ==”123″)
{
session_start();
$_SESSION['auth'] = true;//認證成功,設定一個session變數
header(’Location: ex7.php’);
exit;
}
else
{
$message=”帳號或密碼錯誤”;
}
}
?>
<form action=”ex7-login.php” method=”post”>
<table width=”200″ border=”1″>
<tr>
<td>帳號</td>
<td><input type=”text” name=”Usename” ></td>
<td><?php echo $message?> </td>
</tr>
<tr>
<td>密碼</td>
<td><input type=”password” name=”Password”></td>
<td><input type=”submit” name=”Submit” value=”登入” /></td>
</tr>
</table>
</form>
//ex7.php
<h1>ex7-登入/登出網站的PHP程式</h1>
<img src=”001-03.png” width=”974″ height=”150″ />
11
五月
程式設計二程式 05/11: ex6
import java.io.*; //Mid1a int a, b, c, all; a = Integer.parseInt(args[0]); all = a * 5 + b * 2 + c; System.out.printf("input=(%d, %d, %d) ans = %d", a, b, c, all); //Mid1b import java.io.*; public class Mid1b { public static void main(String[] args) { // TODO Auto-generated method stub try{ FileWriter writer = new FileWriter("package.txt"); PrintWriter pw = new PrintWriter(writer); int largeCount = 1000/5; for (int i=largeCount; i>=0; i--) { int j = (1000 - 5 * i)/2; System.out.printf("Large= %3d Small = %3d\n" , i, j); pw.printf("Large= %3d Small = %3d" , i, j);pw.println(); } pw.close(); } catch(FileNotFoundException fe) { System.out.printf(fe.getMessage()); } catch(IOException ie) { System.out.printf(ie.getMessage()); } } }