drq231358 2019-06-19 23:02
浏览 85

可以使用此代码来验证$ _GET变量吗?

I am building a page where GET parameters are used and i am wondering if this piece of code successfully evaluates the next conditions: $_GET["id"] must be an integrer and $_GET["status"] must be a "true" or "false".

$rawId = $_GET["id"];
$rawStatus = $_GET["status"];

$Id = filter_var($rawId, FILTER_SANITIZE_NUMBER_INT);
$Id = filter_var($Id, FILTER_VALIDATE_INT);

if (!$Id) {
    die();
}

if ($rawStatus != "true" && $rawStatus != "false") {
    die();
}
  • 写回答

3条回答 默认 最新

  • doom910730 2019-06-19 23:13
    关注

    You can use is_int and is_bool to achieve this. Make sure you are also checking if the $_GET vars are set before you do this to avoid potential notices

    $rawId = (isset($_GET["id"]) ? $_GET["id"] : null);
    $rawStatus = (isset($_GET["status"]) ? $_GET["status"] : null);
    
    if (!is_int($rawId)) {
         //handle
    }
    
    if (!is_bool($rawStatus)) {
         //handle
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器