For those of you that want to have your website so each page is displayed in the browser as "index.php?page=home" and so forth but don't know how, look no further, the answer is right here!
First you need to create an index.php file and in it write the following code:
Now to break the code down.
To retrieve the variable 'page' from the address (index.php?page=page)
To prevent any misuse (I.E. Changing directories)
To add ".php" to the end of the page name
This checks if the file $page exists and to prevent a continuous loop, that it is not this page. Then it includes the file if it does exist, and if not, includes the home page.
First you need to create an index.php file and in it write the following code:
| Code: |
| <?php
$page = $_GET['page']; $page = str_replace('..','',$page_name); $page .= ".php"; if (file_exists($page AND $page != "index.php")) { include($page); } else { include("home.php"); } ?> |
Now to break the code down.
To retrieve the variable 'page' from the address (index.php?page=page)
| Code: |
| $page = $_GET['page']; |
To prevent any misuse (I.E. Changing directories)
| Code: |
| $page = str_replace('..','',$page_name); |
To add ".php" to the end of the page name
| Code: |
| $page .= ".php"; |
This checks if the file $page exists and to prevent a continuous loop, that it is not this page. Then it includes the file if it does exist, and if not, includes the home page.
| Code: |
| if (file_exists($page AND $page != "index.php")) {
include($page); } else { include("home.php"); } |
