How to strip a GET property from the URL using PHP
- by James
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?