I've fixed it up and tested it, it should be fully working now
PHP Code:
<?php
$documentfolder = 'documents/'; //Put the name of the directory where your documents are located here
$directory = array_flip(scandir($documentfolder)); // scan the files & lists them
if (($_GET["page"]) && (isset($directory[($_GET['page'])]))){ //verifies file
include $documentfolder . ($_GET['page']);} //include the file
else { echo "404 Page Not Found"; } // error if not found
?>
Name this script whatever you want to name it, but just make sure that the directory in line 1 of the script exists and that the page you send exists.
An example of usage:
script would be
public_html/index.php
Directory would be
public_html/documents/
Page to load would be
test.php (Located in the documents directory)
Then test it by using
www.example.com/index.php?page=test.php
If it works it will show test.php within your page when you load it
You create more files in that directory and it will work for each one, just specify it in the url where it say page=test.php change it to page=filename.
Filenames are case sensitive and you have to type the extension.
If you want to not type the extension, you can use this alternate version but it will only work for .php files
PHP Code:
<?php
$documentfolder = 'urlkey/'; //Put the folder where your documents are located here
$directory = array_flip(scandir($documentfolder)); // scan the files & lists them
if (($_GET["page"]) && ((isset($directory[(($_GET['page']) . ".php")])))){ //verifies file
include $documentfolder . (($_GET['page']) . ".php");} //include the file
else { echo "404 Page Not Found"; } // error if not found
?>
Usage is same as normal version except with this you don't have to type .php at the end of the url