Last active
August 29, 2015 13:55
-
-
Save simongcc/8761665 to your computer and use it in GitHub Desktop.
PHP URL Manipulations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// redirect to somewhere else if calling path is not valid(as expected) | |
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; | |
DEFINE('HTTP_ROOT', $_SERVER['HTTP_HOST']); | |
$path_arr = explode("/", $_SERVER['REQUEST_URI']); | |
$url_chk = in_array("path-name", $path_arr); | |
$location = $protocol . HTTP_ROOT . '/somewhere-to-redirect/'; | |
if( !$url_chk ) header("Location: $location"); | |
// require files | |
// if some server forbid using url to require(), use local path instead | |
$path = "/home/somewhere-out-there/"; | |
require_once $path."index.php"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment