Variable passed in GET or POST array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chuck Anderson

    Variable passed in GET or POST array

    I have finally started coding with register_global s off (crowd roars -
    yeay!).

    This has created a situation that I am not sure how I should handle. I
    have scripts (pages) that can receive an input variable from the POST
    array (initial entry) or it could be in the GET array (go back and
    re-edit a form, for instance.)

    In my old sloppy scripting days this was no problem, as I had
    register_global s on and would merely access the the input variable by
    it's local name (whether it was POST or GET made no difference).

    What's the best way to handle this situation where I am not sure if the
    input variable is in the GET array or the POST array? My guess is to
    test for the presence of the variable (isset, != '') in either array and
    then copy it to a local variable from that array.

    Is that the best, only, or most efficient way to handle that?

    --
    *************** **************
    Chuck Anderson • Boulder, CO

    Integrity is obvious.
    The lack of it is common.
    *************** **************
  • onedbguru@firstdbasource.com

    #2
    Re: Variable passed in GET or POST array



    Chuck Anderson wrote:[color=blue]
    > I have finally started coding with register_global s off (crowd roars -
    > yeay!).
    >
    > This has created a situation that I am not sure how I should handle. I
    > have scripts (pages) that can receive an input variable from the POST
    > array (initial entry) or it could be in the GET array (go back and
    > re-edit a form, for instance.)
    >
    > In my old sloppy scripting days this was no problem, as I had
    > register_global s on and would merely access the the input variable by
    > it's local name (whether it was POST or GET made no difference).
    >
    > What's the best way to handle this situation where I am not sure if the
    > input variable is in the GET array or the POST array? My guess is to
    > test for the presence of the variable (isset, != '') in either array and
    > then copy it to a local variable from that array.
    >
    > Is that the best, only, or most efficient way to handle that?
    >
    > --
    > *************** **************
    > Chuck Anderson · Boulder, CO
    > http://www.CycleTourist.com
    > Integrity is obvious.
    > The lack of it is common.
    > *************** **************[/color]


    variables will be in the format:

    $_POST['variablename'] or $_GET['variablename']

    When troubleshooting with PHP it is very easy to insert a phpinfo();
    command in your script and you can see ALL of the possible variables
    and formats of those variables.

    Michael Austin
    Consultant

    Comment

    • Kimmo Laine

      #3
      Re: Variable passed in GET or POST array

      "Chuck Anderson" <websiteaddress @seemy.sig> kirjoitti
      viestissä:U7idn YMyv49cj1LeRVn-tg@comcast.com. ..[color=blue]
      >I have finally started coding with register_global s off (crowd roars -
      >yeay!).
      >
      > This has created a situation that I am not sure how I should handle. I
      > have scripts (pages) that can receive an input variable from the POST
      > array (initial entry) or it could be in the GET array (go back and re-edit
      > a form, for instance.)
      >
      > In my old sloppy scripting days this was no problem, as I had
      > register_global s on and would merely access the the input variable by it's
      > local name (whether it was POST or GET made no difference).
      >
      > What's the best way to handle this situation where I am not sure if the
      > input variable is in the GET array or the POST array? My guess is to test
      > for the presence of the variable (isset, != '') in either array and then
      > copy it to a local variable from that array.
      >
      > Is that the best, only, or most efficient way to handle that?
      >[/color]

      $_REQUEST <-- it contains both $_GET and $_POST variables :)

      --
      SETI @ Home - Donate your cpu's idle time to science.
      Further reading at <http://setiweb.ssl.ber keley.edu/>
      Kimmo Laine <antaatulla.sik anautaa@gmail.c om.NOSPAM.inval id>


      Comment

      • Pedro Graca

        #4
        Re: Variable passed in GET or POST array

        Chuck Anderson wrote:[color=blue]
        > I have finally started coding with register_global s off (crowd roars -
        > yeay!).[/color]

        YEAY!
        [color=blue]
        > This has created a situation that I am not sure how I should handle. I
        > have scripts (pages) that can receive an input variable from the POST
        > array (initial entry) or it could be in the GET array (go back and
        > re-edit a form, for instance.)[/color]

        Why is it not POST again?
        [color=blue]
        > In my old sloppy scripting days this was no problem, as I had
        > register_global s on and would merely access the the input variable by
        > it's local name (whether it was POST or GET made no difference).
        >
        > What's the best way to handle this situation where I am not sure if the
        > input variable is in the GET array or the POST array? My guess is to
        > test for the presence of the variable (isset, != '') in either array and
        > then copy it to a local variable from that array.[/color]

        Just know what you want and use it;
        if you want something in the POSTed data, use $_POST
        if you want something passed in the URL, use $_GET
        [color=blue]
        > Is that the best, only, or most efficient way to handle that?[/color]

        As Kimmo said you can use the $_REQUEST array which is contains
        (almost (*)) all the $_GETs and $_POSTs.

        (*) The $_REQUEST array will *not* have duplicate keys from $_GET,
        $_POST, and $_COOKIE. There's a configuration value that specifies what
        order is followed when PHP builds the $_REQUEST array (default is GPC,
        meaning GET, POST, COOKIE).

        If you have
        $_GET['id'] = 4;
        $_POST['id'] = 14;
        $_COOKIE['id'] = 77;

        $_REQUEST['id'] will be 77.

        I never needed to use $_REQUEST and I always know whether the user input
        comes from $_GET, $_POST, or $_COOKIE.

        --
        If you're posting through Google read <http://cfaj.freeshell. org/google>

        Comment

        • Chuck Anderson

          #5
          Re: Variable passed in GET or POST array

          Kimmo Laine wrote:
          [color=blue]
          >"Chuck Anderson" <websiteaddress @seemy.sig> kirjoitti
          >viestissä:U7id nYMyv49cj1LeRVn-tg@comcast.com. ..
          >
          >[color=green]
          >>I have finally started coding with register_global s off (crowd roars -
          >>yeay!).
          >>
          >>This has created a situation that I am not sure how I should handle. I
          >>have scripts (pages) that can receive an input variable from the POST
          >>array (initial entry) or it could be in the GET array (go back and re-edit
          >>a form, for instance.)
          >>
          >>In my old sloppy scripting days this was no problem, as I had
          >>register_glob als on and would merely access the the input variable by it's
          >>local name (whether it was POST or GET made no difference).
          >>
          >>What's the best way to handle this situation where I am not sure if the
          >>input variable is in the GET array or the POST array? My guess is to test
          >>for the presence of the variable (isset, != '') in either array and then
          >>copy it to a local variable from that array.
          >>
          >>Is that the best, only, or most efficient way to handle that?
          >>
          >>
          >>[/color]
          >
          >$_REQUEST <-- it contains both $_GET and $_POST variables :)
          >
          >
          >[/color]
          Well, heck, that's almost too easy. Thanks.

          --
          *************** **************
          Chuck Anderson • Boulder, CO

          Integrity is obvious.
          The lack of it is common.
          *************** **************

          Comment

          • Chuck Anderson

            #6
            Re: Variable passed in GET or POST array

            Pedro Graca wrote:
            [color=blue]
            >Chuck Anderson wrote:
            >
            >[color=green]
            >>I have finally started coding with register_global s off (crowd roars -
            >>yeay!).
            >>
            >>[/color]
            >
            >YEAY!
            >
            >
            >[color=green]
            >>This has created a situation that I am not sure how I should handle. I
            >>have scripts (pages) that can receive an input variable from the POST
            >>array (initial entry) or it could be in the GET array (go back and
            >>re-edit a form, for instance.)
            >>
            >>[/color]
            >
            >Why is it not POST again?
            >
            >[/color]
            I'm not definitely sure. I scripted these pages a couple of years ago. I
            think it was to provide a look and feel for the user interface I
            preferred. A form button to get there to start with and then for some
            reason a regular link seemed more appropriate for getting back to the
            page. I probably also reused the page/script, but without a form.
            [color=blue][color=green]
            >>Is that the best, only, or most efficient way to handle that?
            >>
            >>[/color]
            >
            >As Kimmo said you can use the $_REQUEST array which is contains
            >(almost (*)) all the $_GETs and $_POSTs.
            >
            >(*) The $_REQUEST array will *not* have duplicate keys from $_GET,
            >$_POST, and $_COOKIE. There's a configuration value that specifies what
            >order is followed when PHP builds the $_REQUEST array (default is GPC,
            >meaning GET, POST, COOKIE).
            >
            >If you have
            > $_GET['id'] = 4;
            > $_POST['id'] = 14;
            > $_COOKIE['id'] = 77;
            >
            >$_REQUEST['id'] will be 77.
            >
            >I never needed to use $_REQUEST and I always know whether the user input
            >comes from $_GET, $_POST, or $_COOKIE.
            >
            >[/color]
            Thanks for that extra bit of info. The correct location will be either
            POST or GET. They will never both be used.

            --
            *************** **************
            Chuck Anderson • Boulder, CO

            Integrity is obvious.
            The lack of it is common.
            *************** **************

            Comment

            Working...