Guest User

WTF

a guest
May 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.52 KB | None | 0 0
  1. -> .htaccess
  2. AddDefaultCharset UTF-8
  3. RewriteEngine ON
  4.  
  5. ErrorDocument 401 /error/401
  6. ErrorDocument 403 /error/403
  7. ErrorDocument 404 /error/404
  8. ErrorDocument 500 /error/500
  9.  
  10. RewriteRule ^(.*)$ index.php?url=$1 [QSA]
  11. -> index.php
  12. <?php
  13.  
  14. if (session_status() == PHP_SESSION_NONE) {
  15.     session_start();
  16. }
  17.  
  18. spl_autoload_register(
  19.     function($className)
  20.     {
  21.         $classPathCore = 'modules/core/'.lcfirst($className).'.inc.php';
  22.  
  23.         if(file_exists($classPathCore)) {
  24.             require($classPathCore);
  25.         } else {
  26.             $classPathParts = explode('_', $className);
  27.             $classPath = 'modules/'.lcfirst($classPathParts[0]).'/'.
  28.             lcfirst($classPathParts[1]).'.inc.php';
  29.  
  30.             if(file_exists($classPath)) {
  31.                 require($classPath);
  32.             } else {
  33.                 header("HTTP/1.0 404 Not Found");
  34.             }
  35.         }
  36.     }
  37. );
  38.  
  39. Core::loadPage();
  40.  
  41. ?>
  42. -> modules/core/core.inc.php
  43. <?php
  44.  
  45. class Core
  46. {
  47.     public static function loadPage()
  48.     {
  49.         $moduleName;
  50.         $moduleAction;
  51.         $moduleParams;
  52.  
  53.         $url = $_GET['url'];
  54.         $urlParts = explode('/', $url);
  55.  
  56.         if(!empty($urlParts)) {
  57.             switch(count($urlParts)) {
  58.                 case 1:
  59.                     $moduleName = array_shift($urlParts);
  60.                     $moduleAction = "default";
  61.                     $moduleParams = null;
  62.                     break;
  63.                 case 2:
  64.                     $moduleName = array_shift($urlParts);
  65.                     $moduleAction = array_shift($urlParts);
  66.                     $moduleParams = null;
  67.                     break;
  68.                 default:
  69.                     $moduleName = array_shift($urlParts);
  70.                     $moduleAction = array_shift($urlParts);
  71.                     $moduleParams = $urlParts;
  72.                     break;
  73.             }
  74.         } else {
  75.             $moduleName = "Main";
  76.             $moduleAction = "default";
  77.             $moduleParams = null;
  78.         }
  79.  
  80.         $controllerClass = $moduleName.'_Controller';
  81.         $controllerAction = $moduleAction.'Action';
  82.  
  83.         if(class_exists($controllerClass)) {
  84.             $controller = new $controllerClass();
  85.  
  86.             if(method_exists($controller, $controllerAction)) {
  87.                 $controller->$controllerAction($moduleParams);
  88.             } else {
  89.                 header("HTTP/1.0 404 Not Found");
  90.             }
  91.         } else {
  92.             header("HTTP/1.0 404 Not Found");
  93.         }
  94.     }
  95. }
  96.  
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment