Skip to content

Instantly share code, notes, and snippets.

@alejandrofloresm
Created August 18, 2016 19:05
Show Gist options
  • Save alejandrofloresm/9fc4886cc6ee554ba373c5e9b9b601fd to your computer and use it in GitHub Desktop.
Save alejandrofloresm/9fc4886cc6ee554ba373c5e9b9b601fd to your computer and use it in GitHub Desktop.
Get the url path of the current file
<?php
function get_this_location_path() {
$parts = parse_url($_SERVER['PHP_SELF']);
if (!isset($parts['scheme'])) {
$parts['scheme'] = "http";
if (isset($_SERVER["HTTPS"]) &&
$_SERVER["HTTPS"] == "on")
{
$parts['scheme'] .= "s";
}
}
if (!isset($parts['host'])) {
$parts['host'] = $_SERVER["SERVER_NAME"];
}
$url = $parts['scheme'] . '://' . $parts['host'] . $parts['path'];
$url = substr($url, 0, strrpos( $url, '/'));
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment