Today I will share a code snippet which will help you get a current URL Without Page Name.
This simple piece of code will do the trick.
If you want more such tips and tricks related to PHP then consider subscribing to our blog.
Enjoy!
<?PHP
function getPath() {
$protocol = strpos(strtolower($_SERVER[SERVER_PROTOCOL]),https) === FALSE ? http : https;
$host = $_SERVER[HTTP_HOST];
$path = substr($_SERVER[SCRIPT_NAME], 0, -strlen(basename($_SERVER[SCRIPT_NAME])));
return $protocol.://.$host.$path;
}
echo getPath();
?>
This simple piece of code will do the trick.
If you want more such tips and tricks related to PHP then consider subscribing to our blog.
Enjoy!