1
六月

程式設計二程式 06/01: ex8

   Posted by: admin   in 103(下)程式設計(二)

//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;

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,

This entry was posted on 星期一, 六月 1st, 2015 at 10:35:14 and is filed under 103(下)程式設計(二). You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment