Get current URL excluding parameters in php

Category
php drupal variables url
Date Created
8th Nov 2009
Last Updated
9th Jul 2010

Get current URL excluding parameters in php

Question

How to get the current URL excluding the parameters using PHP?

Answer

The following will place the first part of the URL (before ?) and place it within the variables $current_url[0] and then prints it out.

<?
$current_url = explode("?", $_SERVER['REQUEST_URI']);
echo $current_url[0] ;
?>

For the URL:

http://mydomain.com/content.php?var=1&name=mike&country=uk

Just:

http://mydomain.com/content.php would be saved within the variable.