Firstly, I don’t know what to call this thing 🙂 I want to know the key, structure and example how to achieve my goal.
Example, I don’t want create separate file like register.php, login.php, about.php faq.php. Here I want the register, login about, faq ,etc will handle by index.php by example, maybe something like index.php?p=register
How do I create page something like that and what this structure called in PHP programming. Let me know.
To provide a more appropriate answer using Neals code, use
basenameto filter out non-essential file information:You could also create a “white list” to ensure that only the proper files get included:
Both ways should be secure, obviously, the white list will be a bit more so. This tact, depending on how you do is generally referred to as “BootStrapping” IE, one entrance page to access the rest.
UPDATE
To further the security, I would set a variable,
$includedwould be sufficient, to add to the pages that are being included. This would prevent direct access to them (assuming thatregister_globalsis turned off like it should be, so something like:Then on
$page.phpat the top you would have something like:Which would prevent calls to
http://yoursite.com/register.phpfrom being allowed to dish out the file. This has it’s negatives to it. Instead of putting the files you are going to be including in the webroot, I would put them outside of the webroot or in an.htaccessprotected directory, which would ensure that users could not access them directly and must access them through the index.php.