Skip to content

Instantly share code, notes, and snippets.

@simongcc
Last active August 29, 2015 13:55
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 simongcc/8761665 to your computer and use it in GitHub Desktop.
Save simongcc/8761665 to your computer and use it in GitHub Desktop.
PHP URL Manipulations
// 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