I have very basic pagination script and search form with ~4 fields, and action="get" now my problem is that, when i submit my form, i get url like this:
user/people/1/?search=true&country=uk&age=20&online=true ... and so on
so after i submit form everything is just fine, but when i go to page 2 my url changes to:
user/people/2
so my search parameters disappears, this is how i render my links
href="user/people/<?=$next?>"
So my question is what is the best way to keep my paramenters, because now i can only think of for loop and build my link by merging all $_GET values, should i do it like that?
Just append
$_SERVER[ 'QUERY_STRING' ](make sure tohtmlspecialchars()it first).By the way, the PHP short tags
<?= ?>are not portable, so you should consider not using those, and using<?php echo ?>instead.Update:
@Wrikken raises a couple of good points in their answer:
1) passing
ENT_QUOTESas the second argument tohtmlspecialchars()would be important if single-quoting the attribute value (or to cover it being changed to being single-quoted in the future). This is easy to forget, for me anyway, since I almost always double-quote attribute values. It’s unfortunate that it further bloats a call that’s already bloated by a long function name.2) If you’re just passing through the query string as-is, then I’d certainly prefer using
$_SERVER[ 'QUERY_STRING' ]instead ofhttp_build_query( $_GET ). If, however, you need to change some of the query params,http_build_query()would be the ticket. You can see an example of that in my PHP faceted browser.