【发布时间】:2014-04-18 15:21:42
【问题描述】:
对不起,如果这是一个常见的问题,但我很难过。
<?php
session_start();
unset($_SESSION['logerror']);
$host="localhost"; // Host name
$db_name="website_database.sqlite"; // Database name
$tbl_name="User"; // Table name
$con= sqlite_open("Website_Database.sqlite");
// username and password sent from form
$username=$_POST['Username'];
$password=$_POST['Password'];
$sql="SELECT * FROM ".$tbl_name." WHERE Username='".$username."' and Password='".$password."'";
$result= sqlite_query($con,$sql);
// Mysql_num_row is counting table row
$count= sqlite_num_rows($result);
// If result matched $username and $password, table row must be 1 row
if($count==1){
// Register username, $password and redirect to file "login_success.php"
session_register("username");
session_register("password");
echo "Login Successful";
}
else {
echo "does this work nikhil";
}
?>
我正在使用 SQLite,它通过 USB 运行。该文件是 website_database.sqlite
该表是用户。里面的数据是用户名:000001和密码:密码
上一个表单来的post数据是这样的
<form action="checklogin.php" method="post">
<div class="wrap"> <!--make a container that will have all our elements and will be the main stucture of you pages-->
<div class="logo"></div><!--The logo container-->
<div class="header_text">Room Booking</div><!--The main header of the fomr-->
<div class="logins_details_container"><!--The top container-->
<table class="fields_container"> <!--A simple 2x2 table for the form. We choose to use table as for this simple kind of stuff helps us to be everything well stuctured and putting less attributes at the css-->
<tr>
<td><span>Username</span></td>
<td><input class="field" id="Username" name="Username" value="" placeholder="" type="text" /></td>
</tr>
<tr>
<td><span>Password</span></td>
<td><input class="field" id="Password" type="Password" name="Password" value="" placeholder="" /></td>
</tr>
</table>
<div class="remeber_me_container"><!--A container for the Remember me text and the checkbox-->
<div class="remember_me">Remember Me?</div>
<input id="remeber_me" name="" value="" type="checkbox" />
</div>
<div class="login_btn"><!-- The login button-->
<input name="login_btn" value="Login" type="submit" />
</div>
</div>
<form/><!-- End of the logins_details_container -->
【问题讨论】:
-
您对 SQL 注入攻击完全开放,如果您还没有被黑客入侵,那么您将被黑客入侵。请使用准备好的/参数化查询来防止这种情况发生。另见:How can I prevent SQL injection in PHP?
-
简单:您的密码表单元素为空白
name="" -
如有疑问,请始终
print_r($_POST);以查看用户名和密码是否得到POSTed。正如 Fred 上面提到的,您的密码名称attribute为空。如果你有enabled error reporting,你会很容易发现的。 -
@user3548794:不用担心 SQL 注入 - 伙计,不!不!
-
@user3548794:好吧,如果你决定成为一名汽车修理工,请提醒我永远不要带着不可靠的刹车把我的车带给你;)