Chklogin.php :
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0, user-scalable=yes"/>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body>
<img src="css/images/head_logo.png"/>
<hr>
<div align=center><b>Mobile Device 資訊查詢平台</b></div>
<hr>
<?php
session_start();
$host="localhost"; // Host name
$username="tyruan"; // username
$password="tyruan"; // password
$db_name="tyruan"; // Database name
$tbl_name="AUTH_TBL_MOBILE"; // Table name
mysql_connect("$host", "$username", "$password");
mysql_select_db("$db_name");
$myusername=mysql_real_escape_string($_POST['username']);
$mypassword=mysql_real_escape_string($_POST['password']);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['username'] = $myusername;
$_SESSION['password'] = $mypassword;
echo "<table align=center>";
echo "<tr><td><a href=header.php >詢價報價進度查詢</a></td></tr>";
echo "</table>";
}
else {
echo "<div align=center style=\"color:#FF0000\"><b>認證未通過</b></div>";
echo "<b>請確認username / password是否正確</b>";
}
?>
</body>
</html>
And codes for
login_success.php :
<?php
session_start();
if(!$_SESSION['username']) {
header("Location: index.html");
exit;
}
else { echo 'Welcome, '.$_SESSION['username'];
header("Location: student-page.html");
}
?>
沒有留言:
張貼留言