#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Location
    Somewhere in England
    Posts
    204
    Rep Power
    31

    If($_SERVER['REQUEST_METHOD']=="GET") vs if (isset($_POST


    Hi

    i have recently taken over a project from another developer, and something he had done boggled me a bit as i have never used it before

    basically he used if($_SERVER['REQUEST_METHOD']=="GET") and i always use if (isset($_POST

    now the application its self was to be a facbook app and the if($_SERVER['REQUEST_METHOD']=="GET") did not work so me changing it to if (isset($_POST worked in the FB tab.

    i suppose my question is why would you use 1 over the other

    Cheers
  2. #2
  3. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4124
    PHP hasn't always had $_GET and $_POST

    It used to be $_REQUEST

    and there was a precedence order as to what you would get in $_REQUEST['foo'] if a varibale called foo was sent in both get and post parts of the request.

    Given that get and post are semantically different, it makes sense to a developer to know which method was used to send the data to the script, so you would look for the request method to choose what you wanted to do with the data.

    Basically, it's code from php versions < 4

    Comments on this post

    • ManiacDan agrees : Only the last line really matters, but good post.
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Location
    Somewhere in England
    Posts
    204
    Rep Power
    31
    Originally Posted by Northie
    PHP hasn't always had $_GET and $_POST

    It used to be $_REQUEST

    and there was a precedence order as to what you would get in $_REQUEST['foo'] if a varibale called foo was sent in both get and post parts of the request.

    Given that get and post are semantically different, it makes sense to a developer to know which method was used to send the data to the script, so you would look for the request method to choose what you wanted to do with the data.

    Basically, it's code from php versions < 4
    thanks for the information on the above 2 helped alot

IMN logo majestic logo threadwatch logo seochat tools logo