Created
June 23, 2020 17:03
-
-
Save wannaphong/8f38e7335a26f33b176b296ab3b240ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<body> | |
<?php | |
session_start(); // ถ้าใช้งาน session อย่าลืม session_start(); | |
if(isset($_POST["logout"])){ // มี SESSION ชื่อ checklogin ให้ทำในส่วนนี้ | |
//unset($_SESSION['checklogin']); // ทำลาย SESSION ชื่อ checklogin | |
$_SESSION['checklogin'] = false; // | |
echo "ออกจากระบบแล้ว"; | |
header("refresh: 2; url=./"); // รีเพจอีก 2 วินาที | |
exit(0); | |
} | |
else if(isset($_POST["username"])){ // ถ้ามีข้อมูล username ส่งเข้ามา | |
if($_POST["username"]=="admin"&&$_POST["password"]=="1234"){ // || หรือ && และ | |
echo("OK"); | |
$_SESSION['checklogin'] = true; // สร้าง SESSION ชื่อ checklogin | |
header("refresh: 2; url=./"); | |
exit(0); | |
} | |
else{ | |
echo("ชื่อ/รหัสผ่านไม่ถูกต้อง"); | |
header("refresh: 2; url=./"); | |
exit(0); | |
} | |
} | |
else if($_SESSION['checklogin']){ // ถ้ามี SESSION ชื่อ checklogin มีค่าเป็น true แสดงว่า login แล้ว | |
echo "<h1>คุณเข้าระบบแล้ว</h1>"; | |
echo '<form action="./index.php" method="post">'; | |
echo '<input type="hidden" name="logout" value="ok">'; | |
echo '<button type="submit">Logout</button>'; | |
echo '</form>'; | |
} | |
else{ | |
echo('<form action="./index.php" method="post">'); | |
echo('user : <input type="text" name="username"><br>'); | |
echo('password : <input type="password" name="password"><br>'); | |
echo('<button type="submit">Login</button>'); | |
echo('</form>'); | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment