PHP - using pathinfo variables makes relative paths inoperative

I hope to get some cms myself. I see that I can infect Apache variables known as PATH_INFO, so I can create dynamic sections on my site (as joomla does).

eg:

stackoverflow.com/index.php/section1/article22

I'm currently developing a function to find out which section and article were requested by doing the following:

$url_seccion = $_SERVER['PATH_INFO'];
$secciones_array =  array_values(array_filter(explode('/', $url_seccion)));

This part is working fine, the problem I am facing is that all the relative paths that I had are now broken. Can someone explain to me why this is happening, and what can I do to solve this problem? (Please do not tell me that I should use absolute paths ...)

+4
1

:

$url = "stackoverflow.com/index.php/section1/article22";
$myArray = array_slice( explode('/', $url), 2 );
echo "section: ". $myArray[0] ."<br /> article: ". $myArray[1]."<br />";
if(isset($myArray[0]))  {
$section = $myArray[0];
} else {
$section = "";
}

if(isset($myArray[1]))  {
$article = $myArray[1];
} else {
$article = "";
}

switch(strtolower($section)) {
default:
echo "home";
break;
case 'section1':
echo "function for find and show my article: ". $article;
break;
}

, db, select, id, Article

index.php, :

.htaccess

Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond $0 !^(index\.php|css|js|img)
RewriteRule ^(.*)$ index.php [L]

index.php:

$url = addslashes($_SERVER['REQUEST_URI']);
$myArray = array_slice( explode('/', $url), 1 );
+1

Source: https://habr.com/ru/post/1624663/


All Articles