473,672 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

May 30 '07 #1
4 4816
Message-ID: <11************ **********@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/
May 30 '07 #2
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.

--
Ra*********@gma il.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
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
http://tobyinkster.co.uk/blog/2007/0...tive-surnames/
May 30 '07 #4
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
802
by: toufik toufik | last post by:
Hi, I've a variable that can come with the GET and POST method, So I use $_REQUEST to get it When I use a simple href href="myFile.php?myVar=value" I have myVAr in the $GET and $_REQUEST arrays. But when I pass throw a javascript function (to do some checks before to call php) href="javascript:myJsFunction('myFile.php?myVar=value','');"
4
5396
by: Geoff Soper | last post by:
I'm working on an authentication system in which it's possible that a user might be requested to log-in as a result of submitting a form if the inactivity timeout is exceeded. In order that they don't lose the information in the form I would like to capture this information ($_RESULT), serialise it and store it in their session. After they've successfully logged in I would like to retrieve this information and put it back in $_RESULT so...
2
1997
by: Geoff Winkless | last post by:
Hi My knowledge of php is regrettably poor but I need to call a third-party php script from within a bash cgi script (don't ask why, it's a long story). Now normally (with eg perl-cgi) to do this I need to set QUERY_STRING and REQUEST_METHOD appropriately; however with php this doesn't work, the $_REQUEST array is empty. $ export QUERY_STRING='test=1&wibble=2';export REQUEST_METHOD=GET;php -n -r 'print_r($_REQUEST);'
2
1847
by: Ken Fine | last post by:
I would like some guidance regarding a "content scanner" I'm trying to build. This ASP widget will automatically scan remote web sites for certain kinds of content using a screen scraping component and simple pattern matching. The widget will generate reports about what it found and where. Ideally, I would like the widget to follow all of the http:// links on the remote page for one level, and scan the child pages for certain kinds of...
7
5024
by: wallacej | last post by:
Hi I have a 2D array : imageTileArray and I would like to traverse it i.e. visit every entry in the array sequentially. I've had a go at doing it myself as follows but i get address violations: for(i=0; i < sizeof(imageTileArray); i++) { for(j=0; j < sizeof(imageTileArray); j++) { //do something
4
4870
by: plmanikandan | last post by:
Hi, I am new to link list programming.I need to traverse from the end of link list.Is there any way to find the end of link list without traversing from start(i.e traversing from first to find the next for null).Is there any way to find the length of linked list in c.My need is to traverse from the end to 5th node Regards, Mani
3
1318
by: James | last post by:
Hi. I have created several Collection objects which inherit from System.Collections.CollectionBase but up until now I've been able to process them according to the order I populate them from a database. Now I want to be able to traverse backwards and forward through items
11
7303
by: jmark | last post by:
I have seen some code like $value = strval($REQUEST); I would like to know what is the use of strval here since $_REQUEST values are strings?
6
2492
by: sathyashrayan | last post by:
Dear Group, Please look at the following demo link. http://www.itsravi.com/demo/new_pms/admin/addproject.php
0
8504
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8419
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8945
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8847
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4242
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2840
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2094
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1839
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.