php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #10502 parsing for HTTP_POST_VARS drops duplicates
Submitted: 2001-04-26 01:41 UTC Modified: 2002-07-09 11:26 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mk at adio dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.4pl1 OS: Linux
Private report: No CVE-ID: None
 [2001-04-26 01:41 UTC] mk at adio dot com
Parsing of a POST drops duplicate variables unless those variables have "[]".  

It's a few lines in Perl to get it, but I need to stay inside PHP....

is there anywhere that the equivalent of thePerl $form field below:
  if ( $ENV{'REQUEST_METHOD'} eq "POST" ) {
  read(STDIN,$form, $ENV{'CONTENT_LENGTH'});
is available in a PHP session...

I need the whole unparsed line, so that I can manage transforming duplicates into an array.

I have a situation where a check-box coded by someone else I have no control over is sending multiple values with the same field name.   Code for parsing into HTTP_POST_VARS discards all but the last name value pair in the Parse stage because, unfortunately the field is not ending in "[]" in the FORM.


... thoughts.

mk@adio.com

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-26 01:49 UTC] cynic@php.net
this is by design. 

take a look at this (you'll have to edit it):

        function _QueryString()
        {
            $qsstr = '' ;
            $qsarr = array() ;
            $QS = strtr( $GLOBALS['HTTP_SERVER_VARS']["QUERY_STRING"] , array( '[' => '' , ']' => '' ) ) ;
            $QS = explode( '&' , $QS ) ;
            foreach( $QS as $q ) {
                $eq = strpos( $q , '=' ) ;
                if( false === $eq ) {
                    $var = $q ;
                    $val = '' ;
                } else {
                    $var = substr( $q , 0 , $eq  ) ;
                    $val = substr( $q , $eq+1 ) ;
                }
                if( isset( $qsarr[$var] ) ) {
                    $qsarr[$var] = array_merge( (array) $qsarr[$var] , array( $var => $val ) ) ;
                } else {
                    $qsarr[$var] = $val ;
                }
                $qsstr .= "$var=$val&" ;
            }
            $this->_QueryString = substr( $qsstr , 0 , -1 ) ;
            $this->QueryString = $qsarr ;
        }

 [2001-04-26 02:04 UTC] cynic@php.net
open again, this won't work for POSTs...
thx to Zak.
 [2002-07-09 11:26 UTC] markonen@php.net
$HTTP_RAW_POST_DATA or $_SERVER["HTTP_RAW_POST_DATA"] with 
the new superglobals is where POST data is. With that, 
cynic's example can be made to work with POST as well. 
Closing this.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 17:01:30 2024 UTC