how do websites do this index.php?something=somepage

前端 未结 6 1205
有刺的猬
有刺的猬 2020-12-16 08:07

i\'ve seen alot of php based websites where no matter where you navigate your stuck at the index.php and some random parameters are passed in the url. and when i take a look

6条回答
  •  情歌与酒
    2020-12-16 08:27

    The way this works is that the application is no longer written as a collection of pages, but as a monolithic whole, divided into multiple files. Put another way, index.php is the application, and it takes parameters to control what part it shows to you.

    There are various ways of passing the page information in in the URL. Using references to actual filenames should not be the first way you try to do it. Instead, divide your application up into different command and sub-commands. Then the first two things tht index.php does are:

    1. Setup the application framework (load common libraries, setup database access, etc etc)
    2. Figure out which command is being requested.

    The second would be a lookup of some sort, either into an array, or looking for a class or perhaps a file in a particular directory. Whatever, it does, it needs to treat it as untrusted data and produce an error page or a default page with an error banner if the command is invalid. (If it is going to be used in a filename, make sure it is suitably transformed [e.g. .php is added] and checked for any jailbreak action [e.g. doesn't have any embedded slashes]).

提交回复
热议问题