dqxsuig64994 2013-10-20 15:54 采纳率: 0%
浏览 37
已采纳

我的代码sql是否可注入? 删除管理员和普通用户在$ _GET中共享的同一页面上的用户

Please view the pastebin containing my members.php file.

The idea is:

An admin & regular user view the member list on the same page....

The only difference IS the admin sees more features like the

edit | Delete | Make admin

So I suppose I was a bit dumb on parsing the deletion of a user through the url $_GET and isset

I tried to make this code anti sql injectable by redirecting a regular user and exiting the script once ?id= is ! equal to ""

if($_GET['id'] != ""){
    if (has_access($session_user_id, 1) === false) {
    header('Location: index.php');
    exit();
    }
$userID = $_GET['id'];
$sql = "DELETE FROM users WHERE user_id='".$userID."'";
$query  = mysql_query($sql);
}

Should I add in a security feature like preg which will stop the script if id= to anything but a number?

Is this even secure?

Here is the code in action on my free web host.

1334.3owl.com/members.php?id=

NOTICE, If you got to

1334.3owl.com/members.php

the id isnt set and I see an error

Notice: Undefined index: id in C:\Users\Max\Documents\xampp\htdocs\hope\members.php on line 78

Hope you guys can help me out!

NOTE: the page has the function

protect();

enabled so you need to be logged in to view the page in the first place

I created two demo accounts:

demouser
demopass

demouser2
thisisapassword

Please login then go to the link

  • 写回答

1条回答 默认 最新

  • dongquepao8653 2013-10-20 16:05
    关注

    Use intval():

    $userID = intval($_GET['id']);
    

    This will guarantee that $userID will be an integer so no SQL injection is possible. For added security you can should make sure that $userID is non-zero:

    if (!$userID)
        die();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试