How to remove GET variable within $_SERVER['QUERY_STRING'] in PHP
I was working on a mysql search script with paging where i had to pass the same GET parameters to page numbers like
search.php?q=what+europe+scripts&page=1
I used $_SERVER['QUERY_STRING'] to get the GET parameters. But the problem i got was when i was in page 2 it would show query string like
search.php?q=what+europe+scripts&page=1&page=2
and if i am in page 5, it would show like
search.php?q=what+europe+scripts&page=1&page=2&page=3&page=4&page=5
This is an unwanted problem and i wanted to strip/remove only the page variable.
If you are in such a situation here is the solution.
1. Use ereg_replace to strip unwanted variable. (or)
list($q) = explode('&',$_SERVER['QUERY_STRING']);
Here the GET variables separated using & and we take only the first value in the array (say q variable).
2. Use SESSIONS to hold just the query variable.
Just store the GET variable by registering a session and use it on pages.
Similar Posts:
- WordPress query posts with tags not working!
- How to filter & escape data from Injection attacks in PHP!
- WordPress – How to get category ID for use in category.php
- Paypal return url issue with missing GET parameters
- How to show adsense on specific posts/pages in WordPress?
- Fixing CPU Exceeded errors and slow MySQL queries with Bluehost!
- [Fix] Fatal error: Unable to read 25447 bytes in index.php
- Fix-> JQuery onclick browser jumps to top of page!
- PHP – check ssl and redirect to https secure page
- how to call a php script from javascript?


January 17, 2009
If am not wrong, You could have maintained the search string in session instead of passing it each and every time in your Query STRING(URL). If you store the search string in your session, only the page number is need to be passed through the QUERY STRING (URL).
-Kathiravan Manoharan
http://kathyravan.blogspot.com