I'm trying to make links to include the current _GET variables.
Example link: <a href="?page=2">Page 2</a>
The current url is: http://example.com/test.php?id=2&a=1
So if someone clicks on the link of page 2 it will take them to: http://example.com/test.php?id=2&a=1&page=2
Currently if they click on the link it takes them to: http://example.com/test.php?page=2
As you can see, I need a way to get the current _GET variables in the url and add them to the link. Advice?
The superglobal entry $_SERVER['QUERY_STRING']
has the query string in it. You could just append that to any further links.
update: The alternate response on this page using http_build_query is better because it lets you add new variables to the query string without worrying about extraneous ?s and such. But I'll leave this here because I wanted to mention that you can access the literal query string that's in the current address.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With