Skip to content

Instantly share code, notes, and snippets.

@ozh
Created June 20, 2013 12:34
Show Gist options
  • Select an option

  • Save ozh/5822331 to your computer and use it in GitHub Desktop.

Select an option

Save ozh/5822331 to your computer and use it in GitHub Desktop.
Get current path in PHP
<?php
function request_path() {
$request_uri = explode('/', trim($_SERVER['REQUEST_URI'], '/'));
$script_name = explode('/', trim($_SERVER['SCRIPT_NAME'], '/'));
$parts = array_diff_assoc($request_uri, $script_name);
if (empty($parts)) {
return '/';
}
$path = implode('/', $parts);
if (($position = strpos($path, '?')) !== FALSE) {
$path = substr($path, 0, $position);
}
return $path;
}
// from: https://coderwall.com/p/gdam2w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment