Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用CodeIgniter将html插入数据库_Php_Codeigniter - Fatal编程技术网

Php 使用CodeIgniter将html插入数据库

Php 使用CodeIgniter将html插入数据库,php,codeigniter,Php,Codeigniter,我想使用户能够使用编辑器(CKEditor)编辑页面 问题是我想防止XSS,所以当我使用时: $this->input->post('content', TRUE) 它还删除了一些html内容,例如以下代码: <script></script><p><span style="color:#800000;">text</span></p> 文本 成为: [removed][removed]<p>&

我想使用户能够使用编辑器(CKEditor)编辑页面

问题是我想防止XSS,所以当我使用时:

$this->input->post('content', TRUE)
它还删除了一些html内容,例如以下代码:

<script></script><p><span style="color:#800000;">text</span></p>
文本

成为:

[removed][removed]<p><span 

[removed][removed]不要使用内置的XSS功能。用它来为你做。这样,您就可以更好地控制哪些内容被删除,哪些内容没有被删除。

您可以使用下面的代码来代替

$content=htmlspecialchars($this->input->post('content')

保存到数据库,在检索时,您可以使用


htmlspecialchars_解码(“您的html代码”)

首先,在保存内容之前,不要修改它。XSS仅在您将某些内容输出到可以执行javascript的上下文中时发生。如果过早筛选,以后将无法利用改进的筛选,也无法查看原始内容。使用ActiveRecord,您不必担心将字符转义到DB。@Winston:XSS和SQL注入(或由于未能正确转义而导致非恶意语法破坏的DB查询)没有任何连接。这不能解决XSS问题(或任何问题,有什么意义?)。