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)
    
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能