สอบถามเกี่ยวกับการ Login โดยเก็บข้อมูลรหัสผ่านเป็นแบบ md5() ครับ
ผมลองทำตามดูแต่ก็ไม่ได้น่ะครับ อันนี้ Codeผมครับ ไม่รู้ว่าผมเขียน code ผิดตรงไหนครับ ?
หน้า index.php
Code (PHP)
<body>
<div class="one" align="center"><h2>ระบบบันทึกผลงานครูและนักเรียน โรงเรียน...</h2></div>
<form name="form1" method="post" action="check_login.php">
<table class="one" width="40%" border="0" align="center">
<tr>
<td class="one" colspan="2" align="center">
<strong>Account Login</strong>
</td>
</tr>
<tr>
<td>
<strong>User ID</strong><br />
<span>รหัสผู้ัใช้</span>
</td>
<td><input type="text" name="userid" maxlength="5" placeholder="UserID" style="height:24px"/></td>
</tr>
<tr>
<td>
<strong>Password<br/></strong>
<span>รหัสผ่าน</span>
</td>
<td><input type="Password" name="password" maxlength="10" placeholder="Password" style="height:24px"></td>
</tr>
<tr>
<td></td>
<td align="left"><input type="submit" name="Submit" value="Login" ></td>
</tr>
<tr align="center">
<td class="two" colspan="2">
<strong>โรงเรียน HHHHH :วิสัยทัศน์<br />ที่อยู่ HHHHHH </strong>
</td>
</tr>
</table>
</form>
</body>
หน้า check_login.php
Code (PHP)
<?php @session_start();
include"connect.php";
?>
<?php
$userid_log = $_POST['userid'];
$password_log = $_POST['password'];
$sql = "SELECT * FROM user WHERE UserID = '".$userid_log."' and Password = '".md5($password_log)."'";
$objQuery = mysql_db_query($dbname,$sql);
$objResult = mysql_fetch_array($objQuery);
if(!$objResult)//ถ้าไม่ีมีข้อมูลในdb
{
?>
<table width="300px" border="1" align="center" >
<tr style="border-collapse:collapse; background-color:#FFF;">
<td bgcolor="#999999" style="height:30px; color:#FFF";>ข้อความแจ้งเตือนจากระบบ!!!!!!</td>
</tr>
<tr>
<td style="color:#F00; height:60px;">ท่านกรอก User ID หรือ Password ไม่ถูกต้อง</td>
</tr>
</table>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<META http-equiv="refresh" CONTENT="4; url=index.php"><?
}
else
{
session_register('sess_adminid');//อักษรสีน้ำตาลคือตัวแปรที่สร้างมาเอง
session_register('log_user');
session_register('log_type');
$_SESSION['log_id'] = session_id();
$_SESSION['log_user'] = $objResult['UserID'];//เอาข้อมูลจาก database มาเก็บไว้ในตัวแปรที่สร้างขึ้นข้างบน
$_SESSION['log_type'] = $objResult['Type'];
if($objResult["Type"] == "ADMIN")
{
header("location:admin_index.php");
}else{
header("location:user_index.php");
}
}
mysql_close();
?>
Date :
2014-11-28 12:35:49
By :
udorn555
แน่ใจหรือเปล่าครับว่าเป็น md5
ทดสอบ
echo md5($psw) แล้วไป เปรียบเทียบ ใน phpmyadmin ตรงๆ เลยครับ
Date :
2014-11-28 12:53:34
By :
Chaidhanan
แน่ใจครับผม รูปใน database ครับ
ภาพจากการ echo ครับ
Date :
2014-11-28 14:11:54
By :
udorn555
บรรทัดที่ 11 ลองสั่ง ดูครับว่า query สำเร็จหรือเปล่าครับ
Code (PHP)
print_r($objResult);
exit();
Date :
2014-11-28 14:28:27
By :
zinlucifer
ได้แบบนี้ออกมาครับ
Date :
2014-11-28 14:49:10
By :
udorn555
ลองใส่
ob_start(); ไว้บรรทัดที่ 1
ob_end_flush(); ใส่บรรทัดสุดท้ายของโปรแกรม
ตัวอย่าง
Code (PHP)
<?PHP
ob_start(); บรรทัดที่ 1
.
.
.
ob_end_flush(); .ใส่หลังจากจบโปรแกรม
?>
ถ้าได้สาเหตุอ่านตาม link นี้ครับ
https://www.thaicreate.com/php/forum/055229.html
Date :
2014-11-28 15:36:09
By :
- -"
Password น่าจะเป็น reserve word หรือเปล่าครับ
`Password` น่าจะต้องมี backquote ครอบนะครับ
Date :
2014-11-28 16:25:44
By :
Chaidhanan
ลองแบบนี้ดูครับ อันนี้ที่ผมทำ
ในเมื่่อ register ตอนแรกเป็น md5 ตอนถอนรหัสก็น่าจะเป็น เข้ารหัสก่อนแล้วไปเทียบใน ดาต้าเบสครับ
หน้ารับค่าแล้วไป เทียบใน DB
Code (PHP)
<?
session_start();
$Email = $_REQUEST["Email"];
$Password = $_REQUEST["Password"];
$CPassword = md5($Password);
$Passwords =md5($CPassword);
include_once("Function/UserDataAccess.php");
$AdminLogin = AdminLogin($Email,$Passwords);
switch ($AdminLogin) {
case FALSE:
$ErrorMassage1 = "Username or Password Incorrect!";
include("index.php");
break;
case ($_SESSION["login"] = $AdminLogin);
$_REQUEST["action"]="Admin/UserOnlineAction";
include("ActionController.php");
}
?>
Date :
2014-11-29 15:13:36
By :
<->
ลองดูแบบนี้ครับ
Code (PHP)
$password_log = md5($password_log);
$usersSQL = "select * from user where UserID='".$userid_log."' and Password='".$password_log."'";
$usersQRY = mysql_db_query($dbname, $usersSQL);
if(mysql_num_rows($usersQRY)<1) err('ไม่พบรหัสผ่านของท่าน !!','errtxt');
Date :
2014-11-30 09:03:19
By :
LAGO
ขอบคุณ ทุกความคิดเห็นและคำแนะนำครับ
ไฟล์ login.php ถูกเรียกใช้จากการ include ครับ
ตอนนี้แก้ได้ละครับ ผมเขียน code ผิดเองครับประกาศตัวแปรใน session ผิดครับ แหะๆ
ขอบคุณคุณ Chaidhanan, LAGO, Guest ที่ให้คำแนะนำครับ ^___^
Date :
2014-11-30 15:30:00
By :
udorn555
Load balance : Server 00