如果在Controller中出现script代码类似

$hello_str='Hello God<script>alert(3);</script>';

那么我不希望在传给view的时候出现弹框,那么就在view文件中使用

use yii\helpers\Html;

并且输出时使用 Html::encode 

<?=Html::encode($view_hello_str);?>

 

还有一种方法就是过滤调script代码:

use yii\helpers\HtmlPurifier;

然后:

<?=HtmlPurifier::process($view_hello_str);?>

输出时只有 Hello God 

使用该方法的目的是为了防止用户恶意传入参数

相关文章:

  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2021-04-02
  • 2021-09-09
  • 2021-09-06
  • 2022-12-23
猜你喜欢
  • 2021-12-09
  • 2021-12-30
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
相关资源
相似解决方案