A straight forward technique to achieve what you want:
- Use mod_rewirte and .htaccess to setup "pretty URLs"
- Have an index.php to receive the requests and process them:
- Create a hash key dynamically for each "page", store it in a database (e.g. MySQL).
- The "special" URL will be constructed from your domain path and the hash key for each page (e.g. http://www.my-domain.com/pages/azXi39444)
- When a user enters the URL, he will get the output that is related to the key that he has used in the URL, and the hash key will be deleted from the database (of flagged as "deleted")
So you create the page, build the URL (as mentioned above) - and send it back as a response to the user.
I will not get into how to setup mod_rewirte and .htaccess but here is a link to a simple guide:
https://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049
An example of an .htaccess file:
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url_params=$1 [L,QSA]
This can be a simple example of an index.php (pseudo code):
<?php
$params = explode('/',$_GET['url_params']);
$hash = $params[0];
// not a real database adapter - but you get the idea..
$db = new DatabaseAdapter('username','password','database');
$result = $db->querySingle("SELECT pageFileName FROM tb_Pages WHERE hash = %1", $hash);
if($result){
// delete the used hash
$db->query("DELETE FROM tb_Pages WHERE hash = %1", $hash);
// include the path of the page for display
include('/mySecretFolder/'.$result->pageFileName );
}else{
echo 'Page not found';
exit;
}
?>
If you want the pages to be completely virtual, you can ditch the concept of including actual files and store the pages content in a database table, then just pull the data from the database and display accordingly with the page hash\id that was given.
A pseudo example for a database table to store virtual pages:
CREATE TABLE tb_Pages
(
PageID INT AUTO_INCREMENT,
CreateDate Timestamp,
HashKey VARCHAR(100) NOT NULL,
HtmlContent TEXT,
INDEX(HashKey),
PRIMARY KEY(PageID)
)ENGINE=InnoDB CHARACTER SET utf8;
With this approach you use the same concept of .htaccess, url rewrite, index.php and generated hash keys, but instead of including actual files - you are fetching the page content from the database and echo it.
Hope it helps a bit.