Ravichandran Jothi
Ravichandran Jothi

Reputation: 3066

How can i get the Querystring from URL?

Hi I have URl like below

http://word.dev.net/apps/website-management?affiliate=true

now I am using $_SERVER['REQUEST_URI'] for getting current url. what I need to do to get the string affiliate=true alone?.. please help me.

Upvotes: 0

Views: 116

Answers (3)

Matyas
Matyas

Reputation: 13712

That is called a GET variable, and you can acces it via the global variable

$_GET['affiliate']

So in your code you would do something like:

if(isset($_GET['affiliate']))
      /*do something with the var*/

or if you are really interested in just the string itself you can access it using the

$_SERVER["QUERY_STRING"]

global variable

Upvotes: 2

gsone
gsone

Reputation: 1231

You can combine $_SERVER['QUERY_STRING'] with parse_url function in PHP (http://php.net/manual/en/function.parse-url.php) to get the url components.

Upvotes: 0

Pekka
Pekka

Reputation: 449783

You are looking for

$_SERVER["QUERY_STRING"]

You can find all (usually) predefined variables in PHP here.

What often helps is doing a phpinfo() that will list all environment and other variables that are currently set.

Upvotes: 7

Related Questions