How to strip a GET property from the URL using PHP
Posted
by James
on Stack Overflow
See other posts from Stack Overflow
or by James
Published on 2010-03-31T18:32:35Z
Indexed on
2010/03/31
18:43 UTC
Read the original article
Hit count: 287
php
I have the following function that get's the current page URL:
<?php
// get current page url
function currentPageUrl() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
echo $pageURL;
}
?>
Which prints:
http://localhost/gallery.php?id=23&type=main
I want to remove "&type=main" which is present in the url. So before echoing $pageURL I add the following line:
$pageUrl = preg_replace("&type=main", "", $pageURL);
But it still returns the full url including type=main. How can I get rid of that from the url?
© Stack Overflow or respective owner