Skip to content

Instantly share code, notes, and snippets.

@olorton
Created November 24, 2014 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olorton/a00d9c7b46be582d7dd6 to your computer and use it in GitHub Desktop.
Save olorton/a00d9c7b46be582d7dd6 to your computer and use it in GitHub Desktop.
Dynamically hide the a website in a directory
<?php
// Your web folder should look like this:
// /change/index.php <-- this file
// /test-123/ <-- The website that you want to test
// Make sure that you have no other files or folders in the root that begin with 'test' (e.g. /testing)
// When you visit /change/ then the test folder will be moved to a new location,
// you will be provided with a link to that new location.
//
// Permissions... The root folder should be writable by the webserver (so it can create new folders), and
// the initial test-123456 directory should also be writable (so that it can delete it).
$rootDir = __DIR__.'/../';
$currentDir = null;
if ($handle = opendir($rootDir)) {
while (false !== ($entry = readdir($handle))) {
if (preg_match("/^test/", $entry)) {
$currentDir = $entry;
}
}
closedir($handle);
}
if ($currentDir !== null && !is_dir($currentDir)) {
$newDir = 'test-' . substr(md5(time()), 0, 6);
rename($rootDir.$currentDir, $rootDir.$newDir);
echo "<html><body><a href='/".$newDir."/'>Current Test</a></body></html>";
} else {
die('Error, could not create new directory');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment