Archive for 三月, 2014

//ex6-registration.php
<?php
require_once("ex6-func.php");
if (isset($_POST["Submit"]))
{
	$SName = $_POST["SName"];
 	$SPassword = $_POST["SPassword"];
	insert_user($SName, $SPassword);
	header('Location: ex6-home.php');
  	exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ex6-registration.php</title>
</head>
 
<body>
<form method="POST" action="ex6-registration.php">
  帳號<input type="text" name="SName" id="SName" /><br/>
  密碼<input type="password" name="SPassword" id="SPassword" /><br/>
  <input type="submit" name="Submit" id="Submit" value="註冊" />
 
</form>
</body>
</html>
========================
//-> ex6-func.php
<?php
function mysql_auth($user, $pwd)
{
   $link = mysql_connect("localhost", "root", "");
   mysql_select_db("asia_user");//asia_user  -   user_account
   $query = "SELECT * FROM user_account WHERE ( user_name='$user' AND user_pwd='$pwd')";
   $result = mysql_query($query);
   $row=mysql_fetch_row($result);
   mysql_close($link);
   return $row;
}
function insert_user($user, $pwd)
{
   $link = mysql_connect("localhost", "root", "");
   mysql_select_db("asia_user");//asia_user  -   user_account
   $query = "INSERT INTO user_account(user_name, user_pwd) VALUES ('$user','$pwd')";
   $result = mysql_query($query);
   mysql_close($link);
}
?>

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,

SELECT * FROM user_account WHERE ( user_name='vincent' AND user_pwd='1234');
INSERT INTO user_account (user_name, user_pwd) VALUES ('wang','1111')";

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,

-- 資料庫: `asia_user`
-- --------------------------------------------------------
-- 表的結構 `user_account`
-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `user_account` (
  `uid` int(11) NOT NULL AUTO_INCREMENT,
  `user_name` varchar(20) NOT NULL,
  `user_pwd` varchar(20) NOT NULL,
  PRIMARY KEY (`uid`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
-- --------------------------------------------------------
-- 轉存資料表中的資料 `user_account`
-- --------------------------------------------------------
INSERT INTO `user_account` (`uid`, `user_name`, `user_pwd`) VALUES
(1, 'vincent', 'abcd'),
(2, 'johnson', '123');

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,

//ex5-home.php
<?php
session_start();
require_once("ex5-func.php");
 
if (isset($_POST["Submit"]))
{
	$SName = $_POST["SName"];
 	$SPassword = $_POST["SPassword"];
	//if ($SName=="vincent" && $SPassword=="abc123")
	if (mysql_auth($SName, $SPassword))
	{
		$_SESSION["auth"] = true;
	}
}
?>
//ex5-func.php
<?php
function mysql_auth($user, $pwd)
{
   $link = mysql_connect("localhost", "root", "");
   mysql_select_db("asia_user");//asia_user  -   user_account
   $query = "SELECT * FROM user_account WHERE ( user_name='$user' AND user_pwd='$pwd')";
   $result = mysql_query($query);
   $row=mysql_fetch_row($result);
   mysql_close($link);
   return $row;
}
?>

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,

//ex4-pic.php
<?php
session_start();
if (!isset($_SESSION['auth'])) {
  header('Location: ex4-home.php');
  exit;
} 
?> 
//->
<body>
<p><a href="ex4-home.php">Home</a>
<?php
if (isset($_SESSION['auth'])) {
  echo '<a href="ex4-logout.php">Logout</a>';
} 
?>
</p> 
<img src="http://sss.xxx/bbb.jpg" width="319" height="630" />
</body>

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,