$GET question, easy one

Discussion in 'PHP' started by Scorpiono, Nov 6, 2008.

  1. #1
    Scorpiono, Nov 6, 2008 IP
  2. dannywwww

    dannywwww Well-Known Member

    Messages:
    804
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #2
    You can use isset to do this.
    
    <?php
    if(isset($_GET['john'])){
    echo "hello John!";
    }
    ?>
    
    PHP:
     
    dannywwww, Nov 6, 2008 IP
  3. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    print_r($_GET);
    PHP:
    ..and you'll see ;)

    Undefined variables in PHP can be NULL, false, 0, '', or Array().
    == false returns always true on any of them, so this is an easy way to check for any undefined or empty variables.

    Use isset() if you just want to check whether a variable has been initialized.
     
    keyaa, Nov 6, 2008 IP
  4. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #4
    Just in case you want to read "john" from that URL (without any id), you can use this
    <?php
    $name = $_SERVER['QUERY_STRING'];
    ?>
    PHP:
     
    xrvel, Nov 7, 2008 IP
    Scorpiono and ez-designs like this.
  5. ez-designs

    ez-designs Well-Known Member

    Messages:
    230
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #5
    One learns a new thing everyday. Thank you!
     
    ez-designs, Nov 8, 2008 IP
  6. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #6
    I believe this is what I was looking for, thank you. rep added.
     
    Scorpiono, Nov 9, 2008 IP
  7. Supah!

    Supah! Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    
    <?php
    if(isset($_GET['john')) {
    echo "Welcome john :D";
    }
    else {
    echo "Hey you're not john!";
    }
    ?>
    
    PHP:
    :D
     
    Supah!, Nov 9, 2008 IP