Re: $_POST, $_GET and $_REQUEST discarding duplicates [message #170799 is a reply to message #170795] |
Sat, 27 November 2010 12:47 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 11/26/2010 6:46 PM, Jerry Stuckle wrote:
> On 11/26/2010 6:07 PM, James wrote:
>> I am working on an application and specifically validating user
>> input. The application can be sent input via POST or GET. One thing
>> I need to catch is duplicate variable names being passed:
>>
>> Take the following string:
>> myapp.php?a=12&a=12
>>
>> If I var dump $_REQUEST then or $_GET I get the following ///
>>
>> array(1) {
>> ["verb"]=>
>> string(8) "a"
>> }
>>
>> The second instance of 'a' is dropped. If I was just using $_GET I
>> would simply pull $_SERVER['QUERY_STRING] up and pass it but for POST
>> data I don't believe I can do this. Can anybody suggest a function
>> that will allow me to find this duplicates in in POST and GET data?
>>
>> I need to do this to pass a series of validation tests, functionally
>> it has little impact. In an odd side to this if I alter the string to
>> myapp.php?a=12&a=13 then var_dumping $_REQUEST results in a big fat
>> null being returned. This I have been able to trap. But duplicate
>> keys and values have got me stumped.
>>
>> Any clues?
>
> Simple - don't use the same name for different values. If you need an
> array for your post, use a[]. That way you'll get $_POST[0], $_POST[1],
> etc.
>
Correction - that should be $_POST['a'][0], $_POST['a'][1], etc.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|