donglian4770 2014-10-10 00:03
浏览 306

如何绕过PHP eval代码中的管道符号(按位OR运算符)

Is there an equivalent in PHP for the bitwise OR operator (pipe symbol | )? I am using wordpress insert php plugin to allow php code in my content entries on posts and pages, and the way the plugin works is to take the code and run an eval statement on it, but eval function hiccups on certain symbols like bitwise OR or double-pipe OR or dollar sign $. I came across the problem while trying to call json_encode with some flags connected by bitwise OR and of course the eval'ed code barfed when run. My solution is to put the code into a function (like json_encode_eval() ) and define the function in functions.php with the call to json_encode ie return json_encode($str, FLAG | ANOTHER_FLAG); , but is there a better solution? Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douye2488 2014-10-10 00:10
    关注

    Check if wordpress is encoding the | to an html escaped code. (Look for any of

    | | | | |
    

    )

    If so, you'll have to unescape it before evalling.

    [I'm pretty sure there's always a better way than evalling user submitted text - you may have a huge security hole there.]

    I tried this and it gives the expected answer:

    <?php
    eval("\$a = 2|1;");
    $b = 2|1;
    
    var_dump($a);
    var_dump($b);
    

    Outputs:

    int(3)
    int(3)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据