PHP登录页面无法正常工作

时间:2015-10-25 09:10:15

标签: php html sql

最近我正在开展另一个关于留言板的项目。

当我完成后端页面并进行一些测试时,会出现一些问题。

我尝试在登录页面上调查(参考:Example code in Pastebin for admin_login.php),我发现即使我的数据库中有某些特定数据,php中的登录脚本也无法正常工作:

 jQuery(function($){
 var file_frame;

 $('#upload-button').on( 'click', function( e ){
    e.preventDefault();
      // If the media frame already exists, reopen it.
if ( file_frame ) {
  file_frame.open();
  return;
}
 // Create a new media frame
file_frame = wp.media({
  title: 'Select or Upload Media Of Your Chosen Persuasion',
  button: {
    text: 'Use this media'
  },
  multiple: false  // Set to true to allow multiple files to be selected
});

 file_frame.on('open', function(){
     console.log("inside open");

 });
    file_frame.on('update', function(){
     console.log("inside update");
 });
file_frame.on('select', function(){

        // This will return the selected image from the Media Uploader, the result is an object
        var uploaded_image = file_frame.state().get('selection').first();
        // We convert uploaded_image to a JSON object to make accessing it easier
        // Output to the console uploaded_image
        console.log(uploaded_image);
        var image_url = uploaded_image.toJSON().url;
        // Let's assign the url value to the input field
        $('#image-url').val(image_url);
    });
    file_frame.open();
});
});

有任何建议可以处理吗?

2015年10月28日更新:

今天我正在做另一项投资,并将我的代码更改为以下内容:

<?php
    if(isset($_POST['usr'])){
            require("connect.php");
            $username=$_POST['usr'];
            $password=$_POST['pwd'];
            $data=mysql_query("select * from admin where usr = '$username' and pwd = '$password'");
            if(mysql_num_rows($data)>=1){
                    header("location:admin_index.php");
            }else{
                    header("location:admin_login.php?msg=error");
            }
    }
?>

我发现了一些问题。

返回0行。

某处需要调整吗?

1 个答案:

答案 0 :(得分:0)

请在connect_settings.php中检查存储连接信息的变量(result from mysql_connect)。 另外,我看到您在查询期间未指定数据库,请检查您是否正在调用

mysql_select_db("my_database")

调用

mysql_query($sql, $connection_variable)

添加存储连接信息的$ connection_variable。

关于你的SQL注入程序的说明:

// username and password sent from form1
$username=$_POST['user'];
$password=$_POST['pass'];

// To protect MySQL injection
$username=stripslashes($_POST['user']);
$password=stripslashes($_POST['pass']);
$username=mysql_real_escape_string($_POST['user']);
$password=mysql_real_escape_string($_POST['pass']); 

您正在使用$ username和$ password进行查询,并且每次都会覆盖它们。只有mysql_real_escape_string结果存储在$ username和$ password中。

所以

// username and password sent from form1
$username=$_POST['user'];
$password=$_POST['pass'];

// To protect MySQL injection
$username=stripslashes($_POST['user']);
$password=stripslashes($_POST['pass']);

没用。 你应该改变它:

// username and password sent from form1
$username=$_POST['user'];
$password=$_POST['pass'];

// To protect MySQL injection
$username=stripslashes($username);
$password=stripslashes($password);
$username=mysql_real_escape_string($username);
$password=mysql_real_escape_string($password);

但我怀疑将striplashes的效果添加到mysql_real_escape_string会增加任何好处。 mysql_real_escape_string有一些与字符编码相关的缺陷使其易受攻击,这只提供了一个基本保护。您应该切换到mysqli_ *函数集或另一个名为PDO的替代函数。