D
D
DEnisLEB2018-05-07 20:53:59
PHP
DEnisLEB, 2018-05-07 20:53:59

Single sign-on file problem, how to solve?

<?php
//установка кодировки
header("Content-Type: text/html; charset=utf-8");
//Обработка запросов
if ($_SERVER['REQUEST_URL'] == '/') {
$Page = 'index';
$Module = 'index';
} else {
$URL_Path = parse_url($_SERVER['REQUEST_URL'], PHP_URL_PATH);
$URL_Parts = explode('/', trim($URL_Path, ' /'));
$Page = array_shift($URL_Parts);
$Module = array_shift($URL_Parts);
if (!empty($Module)) {
 $Param = array();
 for ($i = 0; $i < count($URL_Parts); $i++){
   $Param[$URL_Parts[$i]] = $URL_Parts[++$i];
   }
 }
}
//переадресация между страницами
if($Page=='index')include('page/index.php');
elseif($Page=='login')include('page/login.php');
elseif($Page=='register')include('page/register.php');
?>

(htaccess)
RewriteBase /
Options All -Indexes
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^resource/(.*)$ resource/$l [L]
RewriteRule ^.*$ [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Navigation to these pages does not work

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Buchnev, 2018-05-07
@butschster

Why not mess around and try a simple framework like https://www.slimframework.com/docs/v3/objects/rout...

M
McBernar, 2018-05-07
@McBernar

Your desire to make a router is understandable.
But doing it in one file without classes, without autoload, without mvc, but with a simple elseif is not good. You have chosen the wrong path. What if there are 200 pages? Will you breed for each through elseif?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question