【问题标题】:Codeigniter - htmlspecialchars() on input not workingCodeigniter - 输入时的 htmlspecialchars() 不起作用
【发布时间】:2013-10-31 11:23:15
【问题描述】:

我在input 字段上使用htmlspecialchars() 来阻止user last name 以防止xss,但它不起作用.. 假设$user_data->user_last_name; 是我的user last name,所以我这样做了:

htmlspecialchars( $user_data->user_last_name, ENT_QUOTES, 'UTF-8' );

当我尝试将用户姓氏保存为'Lastname<script>alert("xss")</script>' 时,我收到JS alert'xss' 消息。

有什么线索吗?

【问题讨论】:

    标签: codeigniter input xss htmlspecialchars


    【解决方案1】:

    试试这个,可能有用:

    $string = htmlentities($user_data->user_last_name, ENT_QUOTES, 'ISO-8859-15'); 
    

    在检索您应该使用的输入时:

    $value = $this->input->post('input_name', true);
    

    这里,true 将清除 xss 的输入值。

    【讨论】:

    • 感谢您的努力,后来意识到我看错了-.-"。
    【解决方案2】:

    可以,但是浏览器会将输出解释为 HTML

    // 使用代码上方的简单行来查看真实输出

    <?php
    
    header('Content-Type: text/plain');
    ?>
    

    【讨论】:

      猜你喜欢
      • 2012-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-04
      • 2020-12-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多