$route_part) { if (preg_match("/^[$]/", $route_part)) { $route_part = ltrim($route_part, '$'); $parameters[] = $request_url_parts[$index]; $$route_part = $request_url_parts[$index]; global $$route_part; } elseif ($route_part !== $request_url_parts[$index]) { return; } } // Включение контроллера и вызов метода self::includeControllerMethod($path_to_include); exit(); } // Функция для включения контроллера и вызова метода private static function includeControllerMethod($path_to_include) { list($controller, $method) = explode('@', $path_to_include); $controller = '\App\Controllers\\' . $controller; $objectController = new $controller; $objectController->$method(); } private static function out($text) { echo htmlspecialchars($text); } private static function set_csrf() { if (!isset($_SESSION["csrf"])) { $_SESSION["csrf"] = bin2hex(random_bytes(50)); } echo ''; } private static function is_csrf_valid() { if (!isset($_SESSION['csrf']) || !isset($_POST['csrf'])) { return false; } if ($_SESSION['csrf'] != $_POST['csrf']) { return false; } return true; } private static function notfound() { Page::set('Errors/404'); } public static function redirect($page) { header("Location: {$page}"); } public static function method() { return $_SERVER['REQUEST_METHOD']; } public static function ip() { $fields = array( 'HTTP_CF_CONNECTING_IP', 'HTTP_X_SUCURI_CLIENTIP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR', // more custom fields ); foreach ($fields as $ip_field) { if (!empty($_SERVER[$ip_field])) { return $_SERVER[$ip_field]; } } return null; } public static function checkCurl($url) { $user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0'; $options = array( CURLOPT_CUSTOMREQUEST => "GET", //set request type post or get CURLOPT_POST => false, //set to GET CURLOPT_USERAGENT => $user_agent, //set user agent CURLOPT_COOKIE => "BIRUXSESS_=1;KANDLESERVICETOKEN__779hfh908BNol8FHn7d9MNFOL8fjND8D9MNfdo=BIRUXSERVICE__TOKENYY", //set cookie file CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects CURLOPT_RETURNTRANSFER => 1 ); $ch = curl_init($url); curl_setopt_array($ch, $options); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $httpcode; } }