Retrieve values from URL

Hi fellas,

I need to get the variables from a URL but in my case, I wont know the variable names, is it possible?

Ex.: www.gerep.com.br/blog.php?id=1

In the example I know the variable ID but the user can set any variable he wishes and I need to get this variable.

The user can set the following:

www.gerep.com.br/blog.php?popcorn=1&horse=pink

Thanks in advance

Here I am again, searching hard for it on google, I’ve found it

$_SERVER[‘QUERY_STRING’]

Problem solved =)

The $_GET variable contains an associated array of the query string.

$_GET might contain:

array(
    'id' => 1,
    'popcorn' => 1,
    'horse' => 'pink'
)

So, you can use array_keys($_GET) to get an array such as [‘id’, ‘popcorn’, ‘horse’] of all the fields you can access. In this case they would be $_GET[‘id’] and $_GET[‘popcorn’] and $_GET[‘horse’]


foreach (array_keys($_GET) as $key) {
    echo $key . ' is ' . $_GET[$key] . '<br>';
}