Traversing $_REQUEST array and excluding items

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fred!head

    #1

    Traversing $_REQUEST array and excluding items

    Hi,

    Probably this is a newbie question so I appreciate you bearing with
    me.

    I've got an application where users can create forms with name= values
    they define. I'd like to write a script that traverses the $_REQUEST
    array to pull out each form value and put it into a simple comma-
    delimited feed they can then download as a CSV file. However, I see
    the $_REQUEST array is junked up with lots of form values, some I've
    heard of (PHPSESSID) and other mystery keys (e.g. dbx-pagemeta,
    __utmz).

    My question: how do I programmaticall y avoid these junk values so they
    don't wind up in my feed? Can I create and maintain an array of these
    junk keys then use that array as a filter to sort out only the
    $_REQUEST keys/values that are different? I tried array_diff() and
    array_intersect () but neither gave me the results I wanted. And using
    a long set of conditional operators (e.g. || and XOR) worked only if I
    had 2-3 conditions; more than that let in every $_REQUEST key/value
    pair.

    Any ideas how to do this in a way that lets my users have the
    flexibility of naming their form fields?

    Thanks in advance for any help and/or insight!

    Tim

  • Geoff Berrow

    #2
    Re: Traversing $_REQUEST array and excluding items

    Message-ID: <1180503822.433 289.155150@z28g 2000prd.googleg roups.comfrom
    Fred!head contained the following:
    >Can I create and maintain an array of these
    >junk keys then use that array as a filter to sort out only the
    >$_REQUEST keys/values that are different?
    Yes. Loop through the $_REQUEST array using in_array() to check the
    key is not in your excluded array.

    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • Rami Elomaa

      #3
      Re: Traversing $_REQUEST array and excluding items

      Fred!head kirjoitti:
      Hi,
      >
      Probably this is a newbie question so I appreciate you bearing with
      me.
      >
      I've got an application where users can create forms with name= values
      they define. I'd like to write a script that traverses the $_REQUEST
      array to pull out each form value and put it into a simple comma-
      delimited feed they can then download as a CSV file. However, I see
      the $_REQUEST array is junked up with lots of form values, some I've
      heard of (PHPSESSID) and other mystery keys (e.g. dbx-pagemeta,
      __utmz).
      >
      My question: how do I programmaticall y avoid these junk values so they
      don't wind up in my feed? Can I create and maintain an array of these
      junk keys then use that array as a filter to sort out only the
      $_REQUEST keys/values that are different? I tried array_diff() and
      array_intersect () but neither gave me the results I wanted. And using
      a long set of conditional operators (e.g. || and XOR) worked only if I
      had 2-3 conditions; more than that let in every $_REQUEST key/value
      pair.
      >
      Any ideas how to do this in a way that lets my users have the
      flexibility of naming their form fields?
      >
      Thanks in advance for any help and/or insight!
      Don't use $_REQUEST, but $_POST instead. $_REQUEST is usually littered
      with extra variables as you've noticed. $_POST and $_GET I think should
      be better.

      One thing you could do is put all the form fields in the same array:
      <form method="post" action="">
      <input type="text" name="my_cvs[field1]" />
      <input type="text" name="my_cvs[field2]" />
      <input type="text" name="my_cvs[field3]" />
      ....
      <input type="text" name="my_cvs[fieldN]" />

      <input type="submit" name="submit">
      </form>

      And then use $_POST['my_cvs'] instead of the entire $_POST, that way you
      can be sure you get only the fields you wanted.

      --
      Rami.Elomaa@gma il.com

      "Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
      usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

      Comment

      • Toby A Inkster

        #4
        Re: Traversing $_REQUEST array and excluding items

        Fred!head wrote:
        However, I see the $_REQUEST array is junked up with lots of form
        values, some I've heard of (PHPSESSID) and other mystery keys (e.g.
        dbx-pagemeta, __utmz).
        IIRC, "__utmz" is a cookie used by "Urchin", the stats package that was
        bought by Google, and is now branded as "Google Stats" or some such.

        An easy way to do what you wanted would be:

        $my_request = $_REQUEST;
        unset($my_reque st['__utmz']);
        unset($my_reque st['PHPSESSID']);
        unset($my_reque st['dbx-pagemeta']);

        However, to me, it looks like all these unwanted values are cookies. You
        might want to consider using $_GET or $_POST instead of $_REQUEST.

        --
        Toby A Inkster BSc (Hons) ARCS
        [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
        [OS: Linux 2.6.12-12mdksmp, up 95 days, 15:56.]

        Non-Intuitive Surnames

        Comment

        • Fred!head

          #5
          Re: Traversing $_REQUEST array and excluding items

          Thanks guys for the ideas! (Geoff, I like your sig line, "It's only
          Usenet, no one dies." Indeed, I've got Usent posts going back to the
          early 1990s...)

          Tim

          Comment

          Working...