• View our reviews on Hot Scripts
  • JS Tutorial

Recent Comments

Powered by Disqus

Back to articles

Get full URL of current page

To get full URL of current, you would probably use this code:

echo !empty($_SERVER['HTTPS']) ? 
        "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : 

But, what if you want to modify URL to exclude some parameters, so they won't get added many more then one time, for example when refreshing page.

Then this piece of code might help you. It takes parameter name or array of parameter names, builds current URL and excludes specified parameters (use it without mod rewrite):

function get_out($get = array())
    //checking if is array
        $temp = $get;
        $get = array();
        $get[] = $temp;
    //getting parameter list
    $url = explode("&", $_SERVER['QUERY_STRING']);
    $address = "";
    foreach ($url as $key => $value)
        if($value != "")
            $arr = explode("=", $value);
            //excluding specified parameters
            if(!in_array($arr[0], $get))
                $address = $address.$value."&";
    //building current URL
    $url = (!empty($_SERVER['HTTPS'])) ? 
        "https://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?".$address : 
    return substr($url, 0, strlen($url) - 1);

//passing parameter name to exclude
//$url = get_out("param");

//or array of parameters
$url = get_out(array("param1", "param2"));

echo $url;

You may also be interested in:

Powered by

blog comments powered by Disqus