How do websites make this index.php? something = somepage

I saw a lot of php based sites where it doesn't matter where you go, stuck in index.php, and some random parameters are passed in the url. and when I watch the open source version that does the same thing, index.php has a bunch of inclusions in them

What is the main way I can do the same? Does this include mod rewrite?

thanks

+3
source share
6 answers

I have seen this and personally think it is a terrible design. In particular, because many people are not inclined to sanitize the inclusion parameter, so that someone can include any file that they need, just by going along the relative path.

mod_rewrite URL-, :

/index.php?path=user&include=account

- :

/user/account

:

RewriteEngine On
RewriteBase /
RewriteRule ^(\w+)/(\w+)$ /index.php?path=$1&include=$2 [L]

- :

RewriteRule %{THE_REQUEST} \.php$ [R=404,L]

, , php. RewriteRule ( ), , PHP, , ( POST ).

, , , . , , , (, ). , . .

+6

, PHP. Cold Fusion Fusebox, .

HTML , . , , , , - "? P = contact", .

mod-rewrite - -- (MVC). , URL:

www.mysite.com/infopages/contact

mod rewrite

www.mysite.com/index.php?p=contact

MVC - - - / . .

+2

, , , - :

include("content/".$_GET['something'].".php");

, "-" , index.php? somthing = -, , .

+2

, , , , . , index.php - , , .

URL. , . . tht index.php:

  • ( , ..)
  • , .

- - , , , , . , , . ( , , [, .php ] - (, )).

0

-, .

http://en.wikipedia.org/wiki/Front_controller

PHP-, Joomla, .

- , PHP, - - mod_rewrite, URL .

0

URL , , , . , , CLOB , "" .

, - . . , . - .

- ( ) . , :

$pageName = (array_key_exists("page", $_GET))
          ? $_GET["page"]
          : null;
$currentPage = (array_key_exists($pageName, $pagetab))
             ? $pagetab[$pageName]
             : $pagetab["home"];
0

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


All Articles