drymoeuka282427675 2011-11-28 07:58
浏览 14
已采纳

$ _POST,$ _GET和安全

I'm wondering if $_POST & $_GET can have issues with security.

Let's say i have an AJAX code that sends the data to a PHP file with the following:

if(isset($_POST['id'])) {
  $client_id = mysql_real_escape_string($_POST['id']);
  $client_name = mysql_real_escape_string($_POST['name']);

    //Delete the Client
    $sql="DELETE FROM clients WHERE id='".$client_id."'";
    mysql_query($sql) or die(mysql_error());

    //Client Pages Delete
    $sql="DELETE FROM fanpages WHERE client='".$client_name."'";
    mysql_query($sql) or die(mysql_error());

Now let's say the PHP file name is delete.php any user can just write something like delete.php?id=423&name=Jack and it will shout the query and delete the client?

I was thinking about adding a COOKIE check at the beginning but as far as i know COOKIE's can be faked as well, am i right?

So what is the solution for making safe $_POST & $_GET requests with the combination of DB quires?

EDIT: All this happens inside of a user-password secured area but I'm asking about the sole delete.php file, do i need to add a COOKIE check to this file as well?

EDIT2: The script is working with COOKIE's not SESSIONS, should i add SESSIONS to the system as well? is it necessary to have cookies and session on the same system?

  • 写回答

3条回答 默认 最新

  • dongtangjie0495 2011-11-28 08:01
    关注

    The trick is to properly escape data and prevent SQL injections. If it comes to deleting a user and you want to be extra safe, you could require a login or something too.

    session_start();
    
    // ...
    
    if (true === $_SESSION['userLoggedIn']) {
        // your code
    }
    

    Of course, this would require you to create some sort of authentication procedure after a login form is submitted. (e.g. querying a MySQL database and testing the username and password against a table of users)

    Here is a great example!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛