|
|
|
ช่วยตรวจสอบให้หน่อยคะว่าผิดตรงไหนทำหน้าlogin ทำไมถึงloginได้ทั้งๆที่ีuser pass ใส่ถูกก็ขึ้นเตือนใส่รหัสผิด echoดูก็แสดงแต่รหัสที่เราใส่ |
|
|
|
|
|
|
|
Code (PHP)
<?php
include("connect.php");
$ID=@$_REQUEST['ID'];
$Password=@$_REQUEST['Password'];
$sql="select count (ids) as rnt from Accmain where ID='$ID' and Password='$Password'";
$query=odbc_exec($link,$sql);
$num=odbc_result($query,1);
$sql1="select count (id) as rnt from Accdetail where ID='$ID' ";
$query1=odbc_exec($link,$sql1);
$num1=odbc_result($query1,1);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Sufee Admin - HTML5 Admin Template">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="apple-icon.png">
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="assets/css/normalize.css">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/themify-icons.css">
<link rel="stylesheet" href="assets/css/flag-icon.min.css">
<link rel="stylesheet" href="assets/css/cs-skin-elastic.css">
<!-- <link rel="stylesheet" href="assets/css/bootstrap-select.less"> -->
<link rel="stylesheet" href="assets/scss/style.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css'>
<!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/html5shiv/3.7.3/html5shiv.min.js"></script> -->
</head>
<script type="text/javascript">
function chk_unit(){
if(document.form1.Username.value==""){
alert('กรุณณากรอกชื่อที่ใช้เข้าสู่ระบบ');
document.form1.Username.focus();
return false;
}
if(document.form1.Password.value==""){
alert('กรุณณากรอกรหัสผ่าน');
document.form1.Password.focus();
return false;
}
}
</script>
<body class="bg-dark">
<div class="sufee-login d-flex align-content-center flex-wrap">
<div class="container">
<div class="login-content">
<div class="login-logo">
<a href="index.php">
<img class="align-content" src="images/logo.png" alt="">
</a>
</div>
<div class="login-form">
<form method="post" enctype="multipart/form-data" name="form1" id="form1" action="">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" name="Username" placeholder="Username">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" name="Password" placeholder="Password">
</div>
<button type="Submit" name="Submit" class="btn btn-success btn-flat m-b-30 m-t-30" onclick="return chk_unit();">Sign in</button>
<div class="social-login-content"></div>
</form>
</div>
</div>
</div>
</div>
<script src="assets/js/vendor/jquery-2.1.4.min.js"></script>
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/plugins.js"></script>
<script src="assets/js/main.js"></script>
<?php
/*if(!empty($_POST['Username']) ){
$ID = $_POST['Username'];
echo $sql="select * from Accdetail where ID='$ID' order by Date_due desc ";
$query=odbc_exec($link,$sql);
$result = odbc_fetch_array($query);
echo "<meta http-equiv='refresh' content='0;URL=index.php'>";
if($result['ID'] == ''){
echo '<span class="style13">username หรือ Password ไม่ถูกต้อง </span>';
}
}*/
if(isset($_POST['Submit'])){
$ID = $_POST['Username'];
$Password = $_POST['Password'];
echo $sql="select count (ids) as rnt from Accmain where ID='$ID' and Password='$Password'";
$query=odbc_exec($link,$sql);
$num=odbc_result($query,1);
if ($rowcount == 1){
while($row = odbc_fetch_array($result)){
$ID = $row['ID'];
$Password = $row['Password'];
}
$_SESSION['user_ID']=$ID;
$_SESSION['user_Password']=$Password;
echo "<script 'type=text/javascript'>alert('ยินดีต้อนรับเข้าสู่ระบบ')</script>";
echo "<meta http-equiv='refresh' content='0;URL=index.php'>";
}else{
echo"<script type='text/javascript'>
alert('username หรือ password ผิด')</script>";
}
}
?>
<?php /*?><?php
if(isset($_POST['btn_save'])){
$sql = "select * from Accmain where ID = '$_POST[ID]'
and Password = '$_POST[Password]' ";
//echo $sql;
$result = $cls_con->sqlselect_base($sql);
$rowcount = $cls_con->sqlselect_numrows($sql);
if ($rowcount == 1){
while($row = mysqli_fetch_array($result)){
$id = $row['ID'];
$Pass = $row['Password'];
}
$_SESSION['user_id']=$id;
$_SESSION['user_pass']=$Pass;
echo "<script 'type=text/javascript'>alert('ยินดีต้อนรับเข้าสู่ระบบ')</script>";
echo "<meta http-equiv='refresh' content='0;URL=index.php'>";
}
else{
echo"<script type='text/javascript'>
alert('username หรือ password ผิด')</script>";
}
}
?><?php */?>
</body>
</html>
Tag : PHP, Ms SQL Server 2016, Google Chrome, Bootstrap Framework, Apache, XAMPP
|
|
|
|
|
|
Date :
2018-07-23 10:57:40 |
By :
mewhappy |
View :
654 |
Reply :
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตรวจสอบว่าเข้าไปใน นี้จริงหรือเปล่า
if(isset($_POST['Submit'])){
วิธีการก็คือ echo ข้อความตรวจสอบไว้ใน if
Code (PHP)
if(isset($_POST['Submit'])){
echo ' TEST pass';
....
|
|
|
|
|
Date :
2018-07-23 14:00:54 |
By :
{Cyberman} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คำสั่งในการ Query เยอะเกินไป ทำให้ ระบบ Query มั่วๆ
วิธีแก้ ไปศืกษาการเขียนระบบ Login มาใหม่
---------------------------------------------------
ลบ 7-13 ออก
---------------------------------------------------
136 - 160 เป็น Code ที่ดีที่สุดในหน้านี้แล้วครับ
|
|
|
|
|
Date :
2018-07-24 08:24:01 |
By :
Hararock |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คำถาม(ตอบตัวเอง)
1. $rowcount มาจากไหน ไม่เห็นประกาศ
2. $_SESSION['user_Password'] ทำไมต้องเก็บ ไม่ควรเก็บไว้ในตัวแปรใดๆ ใช้เฉพาะตอนตรวจสอบการเข้าระบบเท่านั้น
ลองดโค้ดด้านล่างนี้ดูครับ ถ้าไม่ได้ก็ลองปรับดู
Code (PHP)
if(isset($_POST['Submit'])){
$ID = $_POST['Username'];
$Password = $_POST['Password'];
echo $sql="select count (ids) as rnt from Accmain where ID='$ID' and Password='$Password'";
$query=odbc_exec($link,$sql);
$num=odbc_result($query,1);
$row = odbc_fetch_array($result);
if ( ! empty($row['ID']) ){
$_SESSION['user_ID'] = $row['ID'];
//$_SESSION['user_Password'] = $row['Password']; #ไม่ควรเก็บไว้ในตัวแปรใดๆ ใช้เฉพาะตอนตรวจสอบการเข้าระบบเท่านั้น
echo "<script 'type=text/javascript'>alert('ยินดีต้อนรับเข้าสู่ระบบ')</script>";
echo "<meta http-equiv='refresh' content='0;URL=index.php'>";
}else{
echo"<script type='text/javascript'>
alert('username หรือ password ผิด')</script>";
}
}
|
|
|
|
|
Date :
2018-07-24 10:48:42 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|