1.新建中介軟體
php artisan make:middleware XSS
2.在中介軟體中新增以下內容
public function handle(Request $request, Closure $next)
{
$userInput = $request->all();
array_walk_recursive($userInput, function (&$userInput) {
$userInput = strip_tags($userInput);
});
$request->merge($userInput);
return $next($request);
}
3.在Kemel中註冊此中介軟體到路由中介軟體
'xss' => \App\Http\Middleware\XSS::class
4.在路由中應用即可
Route::group(['middleware'=>'XSS', function() {
}]);
本作品採用《CC 協議》,轉載必須註明作者和本文連結