ມາເບິ່ງໃນສ່ວນ ໜ້າ Login.php
========================================================
1. login.php
========================================================
<?php
ob_start();
session_start();
?>
<?php
// connect oop mysqli
$localhost = "localhost"; //localhost server ຈຳລອງຜ່ານ web server Xampp,Appserv
$root = "root"; // root ຂອງການຕິດຕັ້ງ ໃນ web server
$pass = "44@44"; // ລະຫັດຜ່ານທີ່ຕິດຕັ້ງໄວ້ ໃນ web server
$db = "mydatabase"; // database ທີ່ຕ້ອງການຈະຕິດຕໍ່
$con= new mysqli($localhost,$root,$pass,$db); // connection
mysqli_query($con,"set names utf8"); // set ພາສາ ເພື່ອອ່ານພາສາລາວ ໄທ ອື່ນໆ
// check connection or die
// ເມື່ອ Error ຈະຂຶ້ນສະແດງ ຂໍ້ຄວາມຕ່າງໆ ແຕ່ຖ້າຫາກ Connection ສຳເລັດ ສະບໍ່ມີຂໍ້ຄວາມຫຍັງຂຶ້ນ
if($con->connect_errno){
echo $con->connect_error;
exit;
}
// end to connection statement
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Login</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-Edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<style type="text/css">
body{
font-family:'Saysettha MX',Phetsarath OT,Saysettha OT,sans-serif;
font-size:12.5px;
src:url(saysettha-web/fonts/saysettha_web.woff);
src:url(saysettha-web/fonts/saysettha_web.eot);
}
@font-face{
font-family:'Saysettha MX',Phetsarath OT,Saysettha OT,sans-serif;
font-size:12.5px;
src:url(saysettha-web/fonts/saysettha_web.woff);
src:url(saysettha-web/fonts/saysettha_web.eot);
}
</style>
<body>
<form action="" name="frm" id="frm" method="post">
<p align="center">
<?php
if(isset($_POST["ok"])){
$username = $_POST["username"];
$username = $con->real_escape_string($username);
$password = $_POST["password"];
$password = $con->real_escape_string($password);
$Login = $con->query(" SELECT * FROM login
WHERE UserName ='".$username."'
AND Pass = '".$password."'
");
$lognum = $Login->num_rows;
$row = $Login->fetch_assoc();
if($lognum > 0){
$_SESSION['ID'] = $row['ID'];
$_SESSION['UserName'] = $row['UserName'];
$_SESSION['Pass'] = $row['Pass'];
$_SESSION['Name'] = $row['Name'];
echo "<span style ='color:#008000';> ";
echo "ຍິນດີຕ້ອນຮັບເຂົ້າສູ່ລະບົບ";
echo "</span>";
echo "<meta http-equiv='refresh' content='1;url=./main.php'>";
echo "</p>";
}else{
echo "<span style ='color:#F08080';> ";
echo "password And Username ບໍ່ຖືກຕ້ອງ";
echo "</span>";
echo "<meta http-equiv='refresh' content='1;url=./login.php'>";
}
}
?>
</p>
<h2 align="center"> From Login </h2>
<table border="1" width="500" cellpadding="1" cellspacing="1" align="center">
<tr>
<td>User Name </td>
<td><input type="text" placeholder="Username" name="username" id="username" required=""></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" id="password" required placeholder="Password" ></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="ok" id="ok" value="LOGIN" ></td>
</tr>
</table>
</form>
</body>
</html>
========================================================
2. main.php
========================================================
<?php
ob_start();
session_start();
echo "Test Login to Main.php".'<br>';
echo "======================".'<br>';
echo 'ID Login = '.$_SESSION['ID'].'<br>' ;
echo 'UserName = '.$_SESSION['UserName'].'<br>' ;
echo 'Your Password = '.$_SESSION['Pass'].'<br>' ;
echo 'Your Name = '.$_SESSION['Name'].'<br>' ;
echo "======================";
?>
========================================================
Out Put
Login.php |
main.php (welcome when login success) |
ไม่มีความคิดเห็น:
แสดงความคิดเห็น