Traversing $_REQUEST array and excluding items

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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

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,

My question: how do I programmatically 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

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!


Re: Traversing $_REQUEST array and excluding items

Fred!head contained the following:

Quoted text here. Click to load it

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

Re: Traversing $_REQUEST array and excluding items

Fred!head kirjoitti:
Quoted text here. Click to load it

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">

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


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

Re: Traversing $_REQUEST array and excluding items

Fred!head wrote:

Quoted text here. Click to load it

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;

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

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...)


Site Timeline