I’d like to create a link that changes a PHP $_GET variable. For example:
URL: http://site.com/index&variable=hello&anothervariable=dontchangeme
<a href="variable=world">Click me</a>
(after click)
URL: http://site.com/index&variable=world&anothervariable=dontchangeme
I know you can do this to just change the page (href="1.html"), but I’d like to do the same thing while maintaining the GET variables that were already there.
See http://php.net/http_build_query. That’s the easy to understand minimal version. Correctly you need to also HTML-escape the generated query string (because you’re putting it into HTML):