|
|
|
ช่วยแก้ codeให้ด้วยครับ ระบบ login ส่งข้อมูลไปได้แค่หน้าเดียวพอไปหน้าอื่นหรือรีเฟรชก็หลุดจากระบบทันที ขอบคุณครับ |
|
|
|
|
|
|
|
คือผมเขียนโค้ดในส่วนที่ใช้loginกับตรวจcookie+sessionในแต่ละหน้าเสร็จแล้ว แต่ระบบตรวจสอบให้ผมแค่ครั้งเดียวหลังจากloginพอรีเฟชอีกทีหรือไปหน้าอื่นก็หลุดอ่าครับ
Session
- logon
- mainusername
- mainpassword
- otp
cookie
- mainusername
- mainpassword
- otp
http://kingdomofgolf.tk
default file code
Code (PHP)
<?php
session_start();
require("header.php"); ?>
<!--Pagecode-->
<div class="alert alert-error">ระบบนี้ถูกพัฒนาขึ้นโดย KingdomOfGolf<br>
<strong>อยู่ในระหว่างการพัฒนา</strong></div>
</div>
<?php require("footer.php"); ?>
header file
Code (PHP)
<?
require("function/pass_encode.php");
require("function/db1_connect.php");
mysql_select_db($db1_name);
if (isset($_COOKIE["mainusername"]))
{
if (checkPassword($_SESSION["mainusername"],decode($_SESSION["mainpassword"])))
{
if(checkPassword($_COOKIE["mainusername"],decode($_COOKIE["mainpassword"])))
{
if (checkotp($_COOKIE["otp"]))
{
$_SESSION["logon"]=1;
}
else
{
session_destroy();
setcookie("mainusername");
setcookie("mainpassword");
setcookie("otp");
}
}
else
{
session_destroy();
setcookie("mainusername");
setcookie("mainpassword");
setcookie("otp");
}
}
else
{
session_destroy();
setcookie("mainusername");
setcookie("mainpassword");
setcookie("otp");
}
}
else
{
if (checkPassword($_SESSION["mainusername"],decode($_SESSION["mainpassword"])))
{
if (checkotp($_COOKIE["otp"]))
{
$_SESSION["logon"]=1;
}
else
{
session_destroy();
setcookie("mainusername");
setcookie("mainpassword");
setcookie("otp");
}
}
else
{
session_destroy();
setcookie("mainusername");
setcookie("mainpassword");
setcookie("otp");
}
}
?>
Login Check file
Code (PHP)
<?php
session_start();
$ref = $_SERVER['HTTP_REFERER'];
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>KingdomofGolf - Login Check testpage</title>
<link href="../css/bootstrap.css" rel="stylesheet" type="text/css">
<meta http-equiv='REFRESH' content='1;url=<?php echo "$ref"; ?>'>
</head>
<body>
<?php
/////////////////////////////////
////เรียกไฟล์ตั้งค่าและติดต่อฐานข้อมูล1////
/////////////////////////////////
require("../function/pass_encode.php");
/////////////////////////////////
$username=$_POST['username'];
$password=$_POST['password'];
$alwayslogin=$_POST['alwayslogin'];
if(checkPassword($username,$password))
{
?>
<table align='center' width='80%' cellpadding='10'><tr><td align='center'>
<div class="container text-center">
<div class="alert alert-success">
<strong>เข้าสู่ระบบแล้ว</strong><br>
<?php
echo "สวัสดีครับคุณ $username<br>";
$otp=createotp($username);
$_SESSION[logon]="1";
$_SESSION[mainusername]=$username;
$_SESSION[mainpassword]=encode($password);
$_SESSION[otp]=$otp;
if ($alwayslogin=="alwayslogin")
{
setcookie(mainusername,$username,time()+3600*24*356);
setcookie(mainpassword,encode($password),time()+3600*24*356);
setcookie(otp,$otp,time()+3600*24*356);
}
?>
<span class="label label-warning">ระบบนี้เป็นแค่การทดสอบ</span>
</div>
</div>
</td></tr></table>
<?php
}
else
{
?>
<table align='center' width='80%' cellpadding='10'><tr><td align='center'>
<div class="container text-center">
<div class="alert alert-error">
ชื่อผู้ใช้หรือรหัสผ่านผิด
</div>
</div>
</td></tr></table>
<?php
}
?>
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2013-12-31 14:00:27 |
By :
KingdomOfGolf |
View :
1071 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PHP MySQL กับ Login Form ทำระบบ User ล็อกอิน แบบง่าย ๆ ด้วย PHP
ศึกษาให่้เข้าใจก่อนครับ
|
|
|
|
|
Date :
2014-01-01 07:33:06 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|