Archive for 三月 16th, 2012

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

<?
session_start();
session_register('UrlRedirect');
$_SESSION['UrlRedirect'] = $PHP_SELF;
if(empty($_SESSION['authenticated'])||$_SESSION['authenticated']==false)
{
	header('Location: ex4-2.php');
	exit;
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ex4-1</title>
</head>
 
<body>
<form method="post" action="ex4-3.php">
<input type="submit" name="submit" value="登出">
</form>
 
<img src="pic.jpg" width="667" height="132" />
</body>
</html>

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

<?
$AuthMessage="請輸入帳號資料";
include('mysqlauth.php');
if(isset($_POST["Submit"])){
	//
	$Username=$_POST["Uname"];
	$Password=$_POST["Pwd"];
	if (mysql_auth($Username, $Password))
	{
		if(isset($_SESSION["UrlRedirect"]))
		{
			$redir = $_SESSION["UrlRedirect"];
		}
		else
		{
			$redir = 'ex4-1.php';
		}
	//
		session_register('authenticated');
		$_SESSION['authenticated'] = true;
		header("Location: $redir");
		exit;
	}
	else
	{
	    $AuthMessage="認證失敗";
	}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>Ex4-2</title>
<script language="JavaScript">
function checkemail(){
var str=document.myform.Email.value;
if (isValidEmail(str))
{
return true;
}
else{
alert("Please input a valid email address!");
return false;
}
}
function isValidEmail(str) {
return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
</script>
</head>
<body>
<form name="myform" method="POST" action="ex4-2.php" onSubmit="return
checkemail()">
使用MySQL server 帳號認證
<table border="1" width="300">
<tr>
<td>帳號</td>
<td><input type="text" name="Uname" size="20"></td>
</tr>
<tr>
<td>密碼</td>
<td><input type="password" name="Pwd" size="20"></td>
</tr>
</table>
<p>
<input type="submit" value="送出" name="Submit">
<input type="reset" value="重新設定" name="B2">
</p>
</form>
<?
echo $AuthMessage;
?>
</body>
</html>

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

<?
session_start();
session_unset();
session_destroy();
header('Location: ex4-2.php');
exit;
?>

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?
// Pop3 Authentication Functions.
function mysql_auth($user, $pwd)
{
	$ret=false;
	/* Connecting, selecting database */
	$link = mysql_connect("localhost", "db_user", "password")
	or die("Could not connect : " . mysql_error());
	mysql_select_db("coursedb", $link) or die("Could not select database");
	/* Performing SQL query */
	$query = "SELECT * FROM webuser WHERE ( username='$user' AND password='$pwd')";
	$result = mysql_query($query, $link) or die ("Invalid query");
	if (mysql_num_rows($result) == 1) {
		$ret=true;
	}
	/* Free resultset */
	mysql_free_result($result);
	/* Closing connection */
	mysql_close($link);
	return $ret;
}
?>

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,