dongpu5874 2014-03-14 20:19
浏览 30
已采纳

代码逻辑不应允许查询通过,但它仍然执行PHP SQL

I receive a $_GET['id'] from the URL - I want it only numeric if not go to a 404 page. I believe I should work - but I have new relic that tells me otherwise and im stump. (note i'm working with legacy code so I apologize for the mysql_query commands and i'm aware I should be using PDO instead)

    if(isset($_GET['item']) && is_numeric($_GET['item'])) {
        $id = $_GET['item'];
    }
    else {
        $timestamp = date("Y-m-d");
        $get_item = json_encode($_GET['item']);
        $err = date("Y-m-d").": Get Item is wrong:".$get_item."
";
        $file = "/logs/error_log_".$timestamp.".log";
        file_put_contents($file, $err, FILE_APPEND | LOCK_EX);
        header( 'Location: http://www.example.com/404.php' ) ;
    }

    $iquery = "SELECT * FROM products WHERE products_id = $id";
    $iresult = mysql_query($iquery);

    if ($iresult == false) {
        $timestamp = date("Y-m-d");
        $err = date("Y-m-d").": SQL:".$iquery."
";
        $file = "logs/error_log_".$timestamp.".log";
        file_put_contents($file, $err, FILE_APPEND | LOCK_EX);        
        header( 'Location: http://www.examples.com/404.php' ) ;
    }
    $iline = mysql_fetch_array($iresult, MYSQL_ASSOC);

according to my log the query itself receive nothign so $id receives nothing and my log file fires with nothing and new relic fires and tells me that my query is failing.

I don't get it.

  • 写回答

1条回答 默认 最新

  • dongqian6484 2014-03-14 20:30
    关注

    It seems like you expect the script to stop after you call header(), but there's nothing in your code that would cause that to happen. header() just adds an HTTP header to the response; it doesn't end your script. If you only want the query to be executed when $_GET['id'] is numeric then you should do the query inside the first if block, not after the else block.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)