Archive for February 26th, 2008

Function to get a self url of the page

Tuesday, February 26th, 2008

function selfURL()
{
$s = empty($_SERVER[”HTTPS”]) ? ” : ($_SERVER[”HTTPS”] == “on”) ? “s” : “”;
$protocol = strleft(strtolower($_SERVER[”SERVER_PROTOCOL”]), “/”).$s;
$port = ($_SERVER[”SERVER_PORT”] == “80″) ? “” : (”:”.$_SERVER[”SERVER_PORT”]);
return $protocol.”://”.$_SERVER[’SERVER_NAME’].$port.$_SERVER[’REQUEST_URI’];
}

function strleft($s1, $s2)
{
return substr($s1, 0, strpos($s1, $s2));
}
$current_url=”";
$url=selfURL();
$cur_url=explode(”/”,$url);
for($i=0;$i<(count($cur_url)-1);$i++)
{
$current_url.=”$cur_url[$i]”.”/”;
}
echo $current_url;

The above function is to get the url of the current page , This is very useful when u r creating  a activation link or a web site link to users dynamically .

Posted by Suresh B