/*
ระบบ login
http://www.thaiall.com/perlphpasp/source.pl?9116 - mysqlworking.php สร้างตาราง car มี 27 เขตข้อมูล
http://www.thaiall.com/perlphpasp/source.pl?9137 - mysql_update.php การจัดการข้อมูลอย่างง่าย
http://www.thaiall.com/blog/burin/9014/ - ตัวอย่างเมนูแบบต่าง ๆ
https://bootsnipp.com/tags/login - ตัวอย่างฟอร์ม login สวย ๆ
create table members (
id int not null auto_increment,
user varchar(20),
passwd varchar(20),
fullname varchar(40),
stat int,
primary key(id));
1. select.php
ตารางชื่อ car - f1 ถึง f27 แล้วแสดงเฉพาะเขตข้อมูล f1
<?php
$connect = new mysqli("localhost","root","","mysql");
$query = "select * from car";
$result = $connect->query($query);
while ($o = $result->fetch_object()) {
echo $o->f1 . "<br/>";
}
$connect->close();
?>
2. form.htm
<form action=signin.php method=get>
<input name=u><input name=p>
<input type=submit>
</form>
3. signin.php
<?php
session_start();
if($_GET["u"] == 1 && $_GET["p"] == 2) {
$_SESSION["u"] = "1";
echo "<a href=page1.php>page1</a>";
} else {
header("location: form.htm");
}
?>
4. page1.php : album, github
<?php
session_start();
if(!isset($_SESSION["u"]) || strlen($_SESSION["u"]) == 0) {
header("location: form.htm");
exit;
} ?>
Hello world
<a href=signout.php>signout</a>
5. page2.php : pyramid, wordpress, blogger, youtube
6. signout.php
<?php
session_start();
$_SESSION["u"] ="";
unset($_SESSION["u"]);
header("location: form.htm");
?>
7. signin.php
<?php session_start();
$connect = new mysqli("localhost","root","","mysql");
$query = "select * from car where
f1='" . $_GET["u"] . "' and f2 = '" . $_GET["p"] . "'";
$result = $connect->query($query);
if ($o = $result->fetch_object()) {
$_SESSION["u"] = $o->f1;
echo "<a href=page1.php>page1</a>";
} else {
header("Location: form.htm");
}
$connect->close();
?>
https://bootsnipp.com/tags/login
if(isset($_SESSION["id"]) && $_SESSION["id"] == "1") { echo "ok"; } else {
echo '<meta http-equiv="refresh" content="0;url=http://www.yourdomain.com">';
}
header("Location: http://www.example.com/");
exit;
s0 - s8 : "7. พีเอชพี และมายเอสคิวแอล (PHP & MySQL)" - https://www.thaiall.com/php/training49.htm
*/