I'm building a set of pages where I have a number of GET variables and it is often valuable to keep passing it along to the next page. This leads to ugly code where I have to have "if this $_GET variable is set, dynamically add it to this hyperlink". This is, in many senses, not a problem; but I had the thought "there must be a better way to do this", I mean after all basically all I want is to take the '?' and everything after it and append it to the links on that page, it would seem this should be rather simple (or at least possible to do in a for loop). I tried google searching but couldn't find anything, so I figured I'd see if any of you happen to know.
Why not use SESSION? Because these pages need to be capable of being bookmarked.
Thank you.
This variable contains the request parameters. You could pass these to each link on the pages.
eg: foo=test1&bar=test2
Prepend the ? and you are done.
$_SERVER['QUERY_STRING']
A quick idea would be to :
parse_url
to extract the parameters from the current URL to an array$_GET
, which already contains those parametersarray_merge
, to merge :http_build_query
to build the new query-string&
-- which is not always what you need, depending on the kind of output you are generating
And, once you have your new query-string, it's just matter of concatenation :
?
characterANd here you are ;-)