Tutorials Home Scripts Home

Show The URL Of The Page

Show The URL Of The Page

Why This!

For example mabey in a social bookmarking situation.

Firstly you need to put this code on your page

<?php
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));
}
?>

Usage:

Then just simply put the piece of code below on the page and it will show the URL.

<?php
echo 'The Page Url Is:'.selfurl();
?>

Category: Website Programming | Views: 2,232 | on: October 17, 2009 | by: jooria
Enjoyed the article? Subscribe and get the new Tutorials

Enter your email address:

Comments

Comment form

No Comments!

Be the first to review this page !

Leave a Comment

Comment form