SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Location
    Cássia, MG, Brazil
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    SitePoint Member
    Join Date
    Sep 2009
    Location
    Cássia, MG, Brazil
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here I am again, searching hard for it on google, I've found it

    $_SERVER['QUERY_STRING']
    Problem solved =)

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    The $_GET variable contains an associated array of the query string.

    $_GET might contain:

    Code:
    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']

    Code php:
    foreach (array_keys($_GET) as $key) {
        echo $key . ' is ' . $_GET[$key] . '<br>';
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •