|
|
|
สอบถาม code เว็บร้านขายของในการทำ md5()ในการ login มีตัวอย่างที่ลองทำมาให้ดูว่าทำไม่ถึงไม่สามารถทำการ login ได้ |
|
|
|
|
|
|
|
เอามาจากเว็บร้านขายของ และ ทำการใส่ md5()
Code (PHP)
<?
ob_start();
//============ Start Session และทำการเรียก Function ติดต่อฐานข้อมูล
session_start();
require("connect/connect.php");
require("connect/function.php");
//============ อ่านอีเมล์
if($_SESSION["strEmail"] != "")
{
header("location:.");
}
//============ ถ้าเลือกสมัครสมาชิก
if($_GET["action"]=="Register")
{
//============ อ่านว่าอีเมล์นี้เคยสมัครหรือยัง
$result=select("member","where 1 and Email='".$_POST["txtEmail"]."'");
if($result)
{
$_POST["txtEmail"]="";
$_POST["txtEmailCon"]="";
echo "<script language=\"JavaScript\">";
echo "alert('อีเมล์นี้มีคนใช้แล้ว');";
echo "</script>";
}
else
{
//==============MD5
$md5pass=md5($Password);
//============ บันทึกข้อมูลสมาชิก
$sql = "insert into member (Email,Password,Name, LastName,Gender,Address,Province,ZipCode,Tel,Fax) Values ('$_POST[txtEmail]','$md5pass','$_POST[txtName]','$_POST[txtLastName]' ,'$_POST[rdoGender]','$_POST[txtAddress]', '$_POST[txtProvince]','$_POST[txtZipCode]','$_POST[txtTel]','$_POST[txtFax]')";
$dbquery = mysql_query($sql);
$_SESSION["strEmail"]=$_POST["txtEmail"];
$_SESSION["strPassword"]=$_POST["txtPass"];
session_write_close();
header("location:finish.php");
}
}
?>
ในการสมัค สมาชิก ทำการแปลงเป็น md5 ได้ แต่ตอน login ไม่ได้
Code (PHP)
<?
//============ กรณีที่ทำการล็อกอินสมาชิก
if($_GET["action"]=="Login")
{
//============ ตรวจสอบสมาชิก
$resultLogin=select("member","where 1 and Email='".$_POST["txtEmailSC"]."' and Password='".md5($_POST["txtPassSC"])."' ");
if(!$resultLogin)
{
echo "<script language=\"JavaScript\">";
echo "alert('อีเมล์ และ รหัสผ่าน ไม่ถูกต้อง');";
echo "</script>";
}
else
{
//============ บันทึกข้อมูลสมาชิก
$_SESSION["strEmail"]=$_POST["txtEmailSC"];
$_SESSION["strPassword"]=$_POST["txtPassSC"];
session_write_close();
header("location:cart.php");
}
}
?>
Tag : PHP, CakePHP
|
|
|
|
|
|
Date :
2012-09-03 22:17:44 |
By :
suebsuan_jr |
View :
1191 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
echo $resultLogin;
เอา SQL ที่ได้ไปทดสอบดูใน phpMyAdmin ครับ
|
|
|
|
|
Date :
2012-09-04 06:14:25 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูนะค่ะว่าในฐานข้อมูลนั้นเก็บค่า password ไว้กี่ตัวน่ะค่ะเช่น Varchar 20 แต่ถ้าเเปลง password เป็น md5 ความยาวของ password นั้น จะยาวกว่า 20 ตัว ซึ่งในฐานข้อมูลก็จะเก็บไม่ครบน่ะค่ะ ลองโชว์ค่าออกมาดูล่ะกันนะค่ะ
|
|
|
|
|
Date :
2012-09-04 08:18:28 |
By :
OaLunla |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|