 |
|
เป็นโค๊ดเช็ค login ครับเพิ่งหัดเขียนครับ คือต้องการความปลอดภัยและใช้งานได้รวดเร็วครับ และไม่อยากให้มีปัญหากับ HOST ด้วยครับ แตว่าตอนนี้ยังไม่เจอปัญหาอะไรครับ แต่ว่าอยากให้พี่ใน Thaicreate ช่วยปรับปรุงโค๊ดหน่อยครับ รบกวนด้วยครับ
Code (PHP)
<?
session_start();
include('../conf/config_inc.php');
include('../conf/function_inc.php');
include('../conf/setting_inc.php');
$datetime = date("Y-m-d H:i:s");
$checkip = $_SERVER['REMOTE_ADDR'];
switch($_POST['txtUser'])
{
case admin:
echo "<script>alert('อย่าทำหนูเลยนะคร้า ...ท่าน admin');window.location='index.php';</script>";
break;
case Admin:
echo "<script>alert('อย่าทำหนูเลยนะคร้า ...ท่าน Admin');window.location='index.php';</script>";
break;
case ADMIN:
echo "<script>alert('อย่าทำหนูเลยนะคร้า ...ท่าน ADMIN');window.location='index.php';</script>";
break;
case Administrator:
echo "<script>alert('อย่าทำหนูเลยนะคร้า ...ท่าน Administrator');window.location='index.php';</script>";
break;
default:
if($_COOKIE['login'] == "")
{
if($_POST['txtUser'] == "")
{
echo "<script>alert('อย่าลืมใส่ Username ด้วยนะค่ะ');</script>";
logout();
exit();
}
if($_POST['txtPass'] == "")
{
echo "<script>alert('อย่าลืมใส่ Password ด้วยนะค่ะ');</script>";
logout();
exit();
}
if($_POST['txtUser'] != "" and $_POST['txtPass'] != "")
{
$select = select("admin","where user='$_POST[txtUser]'");
$result = mysql_fetch_array($select);
if($_POST['txtUser'] == $result['user'] and base64_encode($_POST['txtPass']) == $result['pass'])
{
$_SESSION['user'] = $_POST['txtUser'];
$_SESSION['pass'] = base64_encode($_POST['txtPass']);
$_SESSION['level'] = $result['level'];
$_SESSION['login'] = true;
# time()+ 86400 = 1 DAY ,31622400 = 1 YEAR
setcookie("user",$_POST['txtUser'],time()+31622400);
setcookie("pass",base64_encode($_POST['txtPass']),time()+31622400);
setcookie("login",true,time()+31622400);
session_write_close();
insert("log","'','$_POST[txtUser]',NOW(),'$checkip','','1'");
echo "<script>alert('ยินดีต้อนรับเข้าสู่ระบบค่ะ คุณ $_SESSION[user]');window.location='main.php';</script>";
# header('location:index.php');
}else{
//ใช้บันทึกสำหรับใช้ user root เข้าระบบ กันการ hacker
if($_POST['txtUser'] == "root")
{
insert("log","'','$_POST[txtUser]:$_POST[txtPass]',NOW(),'$checkip','','4'");
}
echo "<script>alert('ชื่อผู้ใช้ หรือ รหัสผ่านไม่ถูกต้องนะค่ะ');window.location='login.php';</script>";
}
}else{
echo "<script>alert('กรุณาใส่ข้อมูลให้ครบนะค่ะ');window.location='login.php';</script>";
}
}else{
$select = select("admin","where user='$_COOKIE[user]'");
$result = mysql_fetch_array($select);
if($_COOKIE['user'] == $result['user'] and $_COOKIE['pass'] == $result['pass'])
{
$_SESSION['user'] = $_COOKIE['user'];
$_SESSION['pass'] = $_COOKIE['pass'];
$_SESSION['level'] = $result['level'];
$_SESSION['login'] = true;
insert("log","'','$_POST[txtUser]',NOW(),'$checkip','','2'");
session_write_close();
header('location:main.php');
}else{
logout();
echo "<script>alert('ชื่อผู้ใช้ หรือ รหัสผ่านไม่ถูกต้องนะค่ะ');window.location='login.php';</script>";
exit();
}
}
}
?>
Tag : PHP
|
|
 |
 |
 |
 |
Date :
2012-02-18 18:24:33 |
By :
demonking |
View :
1098 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |