By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

Traversing $_REQUEST array and excluding items

P: n/a
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 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
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

May 30 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Message-ID: <11**********************@z28g2000prd.googlegroups .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/
May 30 '07 #2

P: n/a
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 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
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.

--
Ra*********@gmail.com

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

P: n/a
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_request['__utmz']);
unset($my_request['PHPSESSID']);
unset($my_request['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
http://tobyinkster.co.uk/blog/2007/0...tive-surnames/
May 30 '07 #4

P: n/a
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

May 30 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.