10/10/2018, 00:04
Không login được từ form
Sau khi điền đúng user + pass rồi submit thì lại báo lỗi là SAI user + pass
Đây là file form_login.inc show form login nếu chưa login
Đây là file login.php xử lý login hoặc logout
Đây là cấu trúc tlb_user
create table tbl_user
(
user_id int(10) not null auto_increment,
username varchar(32) not null,
password varchar(32) not null,
name varchar(50) not null,
birth_d varchar(10) not null,
birth_m varchar(10) not null,
birth_y varchar(10) not null,
address varchar(50) not null,
email varchar(50) not null,
location varchar(50) not null,
post_number int(11) not null default '0',
PRIMARY KEY (username),
KEY (user_id)
);
Nếu mấy bro vẫn không hiểu được lỗi của em thì down toàn bộ các file có liên quan sau rồi giúp em login từ form với '__'
http://www.box.net/shared/nx3yd8ug4k
Đây là file form_login.inc show form login nếu chưa login
Code:
<?php
if (!isset($_SESSION["ErrMess"])) {$_SESSION["ErrMess"] = ""; }
if ($_SESSION["ErrMess"] !== "")
{
echo "<center><span class="error">".$_SESSION["ErrMess"]."</span>";
$_SESSION["ErrMess"] = "";
}
echo "<form action="login.php?action=login" method="POST">";
echo "<table align="center" border="2">
";
echo " <tr>
";
echo " <td colspan="2" height="30" bgcolor="#E4DAC1" align="center"><b>Dang Nhap</b></td>
";
echo " </tr>";
echo " <tr>
";
echo " <td align="center">Tai khoan</td>
";
echo " <td><input type="text" name= xtuser"></td>
";
echo " </tr>
";
echo " <tr>
";
echo " <td align="center">Mat khau</td>
";
echo " <td><input type="password" name="txtpass"></td>";
echo " </tr>";
echo " <tr>
";
echo " <td colspan="2" align="center"> <input type="submit" value="Dang nhap"> </td>
";
echo " </tr>";
echo "</table>";
echo "</form>";
?>
Đây là file login.php xử lý login hoặc logout
Code:
<?php
include "chk_login.inc";
if (!isset($_GET['action']))
{
$_GET['action']='hura';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table width="400" align="center">
<tr>
<td align="center"><?php
/////////////////////////////
//// logging out ////
/////////////////////////////
$strErrMessage = "Tài khoản hoặc mật khẩu không chính xác!!!";
if ($_GET["action"]=="logout")
{
if (isset($_SESSION["username"]))
{
include "config.php";
include "dbconnect.php";
unset($_SESSION["username"]);
unset($_SESSION["password"]);
echo "<div align="center"> Đăng xuất thành công!<br> Đang chuyển về Trang chủ...</div>";
mysql_close($sqlsv);
}
echo '<script language="javascript"> setTimeout("window.location='."'index.php'".'",3000);</script>';
}
///////////////////////////////////
/////// logging in ///////
///////////////////////////////////
elseif ($_GET["action"] == "login")
{
include "config.php";
include "dbconnect.php";
////////////////////////////////////////////////////
//////////// Select user from database /////////////
$strMyQuery = "SELECT * FROM $strTableUserName WHERE username = '$_POST[txtuser]'";
$result = mysql_query($strMyQuery) or die(mysql_error());
////////////////////////////////////////////////////
/////////// Determine if user exists //////////////
if (mysql_num_rows($result)!==1)
{
$_SESSION["ErrMess"] = $strErrMessage;
echo "<script language="javascript">";
echo "history.back();";
echo "</script>";
}
else
{
$row = mysql_fetch_array($result);
$strPasswordOnServer = $row["password"];
if (crypt($_POST["txtpass"],$strPasswordOnServer) == $strPasswordOnServer)
{
$_SESSION["username"] = $_POST["txtuser"];
$_SESSION["password"] = $strPasswordOnServer;
echo "Đăng nhập thành công!!!";
echo "<script language="javascript">";
echo "window.location = "index.php";";
echo "</script>";
}
else
{
$_SESSION["ErrMess"] = $strErrMessage;
echo "<script language="javascript">";
echo "history.back();";
echo "</script>";
}
}
}
else
////////////////////////////////////////////
/////// Display loggin form ////////
////////////////////////////////////////////
{
include "login_form.inc";
}
?>
</td>
</tr>
</table>
</body>
</html>
Đây là cấu trúc tlb_user
create table tbl_user
(
user_id int(10) not null auto_increment,
username varchar(32) not null,
password varchar(32) not null,
name varchar(50) not null,
birth_d varchar(10) not null,
birth_m varchar(10) not null,
birth_y varchar(10) not null,
address varchar(50) not null,
email varchar(50) not null,
location varchar(50) not null,
post_number int(11) not null default '0',
PRIMARY KEY (username),
KEY (user_id)
);
Nếu mấy bro vẫn không hiểu được lỗi của em thì down toàn bộ các file có liên quan sau rồi giúp em login từ form với '__'
http://www.box.net/shared/nx3yd8ug4k
Bài liên quan





if (crypt($_POST["txtpass"],$strPasswordOnServer) == $strPasswordOnServer)
Chú ý tham số thứ 2 của hàm crypt, khi mã hóa password lên server như thế nào thì mã hóa $_POST["txtpass"] để so sánh phải ý như vậy.
if (md5($pass) == $passOnServer){
//do something
}
Tôi vào database, save lại cái chuỗi md5, sau đó replace = chuỗi md5 của password khác, log vào làm trò bậy bạ rồi lại replace cái chuỗi md5 cũ Đã vào được db thì chuyện gì cũng có thể xảy ra đối với các ứng dụng lưu thông tin hoàn toàn trên db.