【问题标题】:CodeIgniter $this->post() get incorrect stringCodeIgniter $this->post() 得到不正确的字符串
【发布时间】:2013-07-25 07:16:16
【问题描述】:

我正在使用 CodeIgniter 编写一个服务器脚本来将 html 代码存储到数据库中。我的客户发送一个包含 html 字符串的 json 包:

<table style='width:50%'

但从我的服务器端我只能从 $this->post() 获取:

<table >

你知道哪里错了吗?


我的完整错误日志:

我来自客户端的 JSON(通过来自 AngularJS 的 $.param 编码):

apikey=superrocket_51f0c7333392f&faqid=31&categoryid=44&question=How+to+format+the+answer+%3F&answer=%3Ctable+style%3D'width%3A50%25%3B'%3E&displayorder=0

我处理 JSON 的 PHP 代码:

function updateFAQs_post(){
    $auth = $this->_auth();
    if ($auth){
        print_r($this->post('answer'));
        $this->load->model('Admin_model');
        $faqid = $this->Admin_model->updateFAQs($this->post('faqid'), $this->post('categoryid'), $this->post('question'), $this->post('answer'), $this->post('displayorder'));
        $response = array('success' => 'update done', 'faqid' => $faqid, 'index' => $this->post('index'));
        $this->response($response, 200);
    }
}

我从服务器得到的:

<table >{"success":"update done","faqid":null,"index":false}

faqid 和 index = null 是预期的。与错误无关。

我认为错误是由于JavaScript编码方式和PHP解码JSON包方式之间的差异?

【问题讨论】:

  • 我的回答对你有帮助吗?

标签: php json codeigniter


【解决方案1】:

试试

$this->input->post()

不是$this-&gt;post()

$_POST 有效,因为那是原始的 php 函数

【讨论】:

    【解决方案2】:

    我通过将 $this->post('answer') 替换为 $_POST['answer'] 解决了这个问题。

    仍然不知道发生了什么,但它有效

    【讨论】:

    • 你可能想看看这个:stackoverflow.com/questions/3788476/… 我很确定它与 XSS 清理有关,所以你可以暂时禁用它。但更好的是根本没有任何样式标签,也许您可​​以使用 css 类来代替。这不应该触发 XSS 过滤器
    【解决方案3】:
    $this->post('answer');
    

    应该是

    $this->input->post('answer');
    

    【讨论】:

      猜你喜欢
      • 2015-04-21
      • 1970-01-01
      • 2017-07-29
      • 1970-01-01
      • 1970-01-01
      • 2022-06-29
      • 1970-01-01
      • 1970-01-01
      • 2016-09-08
      相关资源
      最近更新 更多