反 XSS PHP 库 (Class 'voku\helper\AntiXSS')
Anti XSS PHP Library (Class 'voku\\helper\\AntiXSS')
我一直在尝试使用这个反 XSS 库:https://github.com/voku/anti-xss/blob/master/README.md
但我收到以下错误:
AH01071: Got error 'PHP message: PHP Fatal error: Class 'voku\helper\AntiXSS' not found in /var/www/vhosts/example.com/httpdocs/xss.php on line 6\n'
这是我使用的代码:
<?php
use voku\helper\AntiXSS;
require_once __DIR__ . '/vendor/autoload.php';
$antiXss = new AntiXSS();
$harm_string = "Hello, i try to <script>alert('Hack');</script> your site";
echo $antiXss->xss_clean($harm_string);
?>
在引用 class 之前需要自动加载。
require_once __DIR__ . '/vendor/autoload.php';
use voku\helper\AntiXSS;
否则,此依赖命名空间将不会加载到上下文中的内存中,因为它已加载到 autoload.php 文件中。这就是为什么它说 class 未找到。
还要确保您已通过 "composer require"
安装
composer require voku/anti-xss
我一直在尝试使用这个反 XSS 库:https://github.com/voku/anti-xss/blob/master/README.md 但我收到以下错误:
AH01071: Got error 'PHP message: PHP Fatal error: Class 'voku\helper\AntiXSS' not found in /var/www/vhosts/example.com/httpdocs/xss.php on line 6\n'
这是我使用的代码:
<?php
use voku\helper\AntiXSS;
require_once __DIR__ . '/vendor/autoload.php';
$antiXss = new AntiXSS();
$harm_string = "Hello, i try to <script>alert('Hack');</script> your site";
echo $antiXss->xss_clean($harm_string);
?>
在引用 class 之前需要自动加载。
require_once __DIR__ . '/vendor/autoload.php';
use voku\helper\AntiXSS;
否则,此依赖命名空间将不会加载到上下文中的内存中,因为它已加载到 autoload.php 文件中。这就是为什么它说 class 未找到。
还要确保您已通过 "composer require"
安装composer require voku/anti-xss