Answer the question
In order to leave comments, you need to log in
How to prevent xss vulnerability on yii2?
For example, you created an action in the controller:
public function actionPage($target = '') {
$get = News::find()->where(['link' => $target])->one();
return $this->render('page', ['target' => $target, 'get' => $get,]);
}
<?php
use yii\helpers\Html;
$this->title = $get->title;
?>
<h1>Hello <?= Html::encode($target) ?></h1>
<p>Welcome to your <?=$get->world;?></p>
<h1><?=$get->header;?></h1>
Answer the question
In order to leave comments, you need to log in
what about xss?
In your case, it will be enough:
public function actionPage($target = '') {
$get = News::find()->where(['link' => $target])->one();
if (null === $get) // В случае неудачного поиска метод one() возвращает null всегда
throw new NotFoundHttpException('Page not found');
return $this->render('page', ['target' => $target, 'get' => $get,]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question