Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to remove all $_GET params except my owns

need to remove all $_GET params from address bar – set by facebook etc – except my own id and title

something like:

if(isset($_GET['any-key-except-id-or-title'])){
    header('location: my-native-url');
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Loop through $_GET and remove any elements with another key. Then use http_build_query() to create a query string based on the remainder.

foreach (array_keys($_GET)) as $key) {
    if ($key != 'id' && $key != 'title') {
        unset($_GET[$key]);
    }
}

header('Location: my-native-url?' . http_build_query($_GET));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading