Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php get all url variables

Tags:

php

get

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?

like image 331
user962449 Avatar asked Nov 27 '22 14:11

user962449


1 Answers

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.

like image 121
octern Avatar answered Dec 06 '22 00:12

octern