Sometimes, you might want to get the current page URL that is shown in the browser URL window. For example if you want to let your visitors submit a blog post to Digg you need to get that same exact URL. Another example maybe a page URL has Querystring info appended to it and you need to send an email off to someone with that same exact URL and Querystring information. There are plenty of other reasons as well. Here is how you can do that.
Add the following code to a 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) {
$values = substr($s1, 0, strpos($s1, $s2));
returnĀ $values;
}
?>
You can now get the current page URL using the line:
<?php
print $currenturl = selfURL();
How you think when the economic crisis will end? I wish to make statistics of independent opinions!
Thanks, it really helped, works perfect.