Search code examples
phpmodel-view-controllerjoomlaquery-string

Strip off specific parameter from URL's querystring


I have some links in a Powerpoint presentation, and for some reason, when those links get clicked, it adds a return parameter to the URL. Well, that return parameter is causing my Joomla site's MVC pattern to get bungled.

What's an efficient way to strip off this return parameter using PHP?

Example: http://mydomain.example/index.php?id=115&Itemid=283&return=aHR0cDovL2NvbW11bml0


Solution

  • The safest "correct" method would be:

    1. Parse the url into an array with parse_url()
    2. Extract the query portion, decompose that into an array using parse_str()
    3. Delete the query parameters you want by unset() them from the array
    4. Rebuild the original url using http_build_query()

    Quick and dirty is to use a string search/replace and/or regex to kill off the value.