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:
- How to filter & escape data from Injection attacks in PHP!
- Fix-> JQuery onclick browser jumps to top of page!
- Fixing CPU Exceeded errors and slow MySQL queries with Bluehost!
- [Fix] Fatal error: Unable to read 25447 bytes in index.php
- how to call a php script from javascript?
- 3 Must Do Things for Wordpress Blog Starters
- PHP – How to get domain name from URL?
- EASY way to install Zend Optimizer in Cpanel
- TinyMCE Slow Loading Problem!
- How to change vBulletin Homepage Title?


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