php class Router private rules public function add url function this-

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
class Router
{
private $rules = [];
public function add($url, $function)
{
$this->rules[$url] = $function;
}
public function route()
{
foreach($this->rules as $key=>$value) {
if ($_GET['_url'] == $key) {
$value();
}
}
}
}
$r = new Router();
$r->add('/test/', 'main');
$r->route();
function main()
{
echo '<h1>XSS</h1>';
}