$_POST case sensitivity

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill H

    $_POST case sensitivity

    I wouldn't consider myself a newbie to PHP since I have never written
    one line of code in it (am a perl guy myself), but part of a team I am
    working with is writing some php interfaces into a database and I
    noticed that they are relaying on HTML form value names to always be
    lowercase in their code (ie $_POST['save'] (fyi that may be typed
    wrong)) and from my experience it is always better, when reading in
    the post information to convert the the form value name to uppercase
    on the off chance that one web page may have NAME="save" and another
    may have NAME="Save", this way you can will always get the value.

    In perl this is easy cause you are pulling in the name / value pairs
    straight from the ENV value. But since, from what I see and they say,
    PHP does this for you and puts it into $_POST, is there a way to tell
    PHP to always convert the name of the value to uppercase?

    Bill H
  • Paul Lautman

    #2
    Re: $_POST case sensitivity

    Bill H wrote:
    >I wouldn't consider myself a newbie to PHP since I have never written
    one line of code in it (am a perl guy myself), but part of a team I am
    working with is writing some php interfaces into a database and I
    noticed that they are relaying on HTML form value names to always be
    lowercase in their code (ie $_POST['save'] (fyi that may be typed
    wrong)) and from my experience it is always better, when reading in
    the post information to convert the the form value name to uppercase
    on the off chance that one web page may have NAME="save" and another
    may have NAME="Save", this way you can will always get the value.
    In my experience php scripts are written to interact with specific web
    pages. You code the web page to match the script that will process its
    input.


    Comment

    • macca

      #3
      Re: $_POST case sensitivity

      $_POST is just another array

      foreach ($_POST as $key=>$value){

      strtoupper($key );

      }

      Comment

      • Tim Roberts

        #4
        Re: $_POST case sensitivity

        Bill H <bill@ts1000.us wrote:
        >
        >...
        >I noticed that they are relaying on HTML form value names to always be
        >lowercase in their code (ie $_POST['save'] (fyi that may be typed
        >wrong))
        Nope, that's correct.
        >...and from my experience it is always better, when reading in
        >the post information to convert the the form value name to uppercase
        >on the off chance that one web page may have NAME="save" and another
        >may have NAME="Save", this way you can will always get the value.
        I find this philosophy interesting. Because these names ARE
        case-sensitive, I would consider it a programming error to use different
        spellings in different web pages. It seems to me that this kind of
        mangling is just hiding errors and inconsistancies . I mean, if the company
        standard is that "<inputfiel d names should always be in lower case", then
        by golly they should always be in lower case, and a programmer who writes
        NAME="Save" has committed an error.
        --
        Tim Roberts, timr@probo.com
        Providenza & Boekelheide, Inc.

        Comment

        • The Natural Philosopher

          #5
          Re: $_POST case sensitivity

          Tim Roberts wrote:
          Bill H <bill@ts1000.us wrote:
          >...
          >I noticed that they are relaying on HTML form value names to always be
          >lowercase in their code (ie $_POST['save'] (fyi that may be typed
          >wrong))
          >
          Nope, that's correct.
          >
          >...and from my experience it is always better, when reading in
          >the post information to convert the the form value name to uppercase
          >on the off chance that one web page may have NAME="save" and another
          >may have NAME="Save", this way you can will always get the value.
          >
          I find this philosophy interesting. Because these names ARE
          case-sensitive, I would consider it a programming error to use different
          spellings in different web pages. It seems to me that this kind of
          mangling is just hiding errors and inconsistancies . I mean, if the company
          standard is that "<inputfiel d names should always be in lower case", then
          by golly they should always be in lower case, and a programmer who writes
          NAME="Save" has committed an error.
          And you end up with the sort of mess this computer is in.
          I decided to include case sensitivity in the OS-X re-format. Now I cant
          install Adobe CS3.

          Adobe being Mac people have always relied on the fact that case didn't
          matter.

          And can't cope with life when it does.

          Its a pain when I have a pair of directories on a samba mount called
          images and Images, and he computer wrecks the whole file system trying
          to work out which is which.

          Comment

          • Geoff Berrow

            #6
            Re: $_POST case sensitivity

            Message-ID: <poj074df5uogtc h41qe5ujc2ells5 8m1fv@4ax.comfr om Tim
            Roberts contained the following:
            >I find this philosophy interesting. Because these names ARE
            >case-sensitive, I would consider it a programming error to use different
            >spellings in different web pages.

            Agreed but it may be sensible to allow for the possibility of the use of
            incorrect case if the people preparing the html are not programmers.
            Thanks to Bill Gates there are a lot of people who do not recognise that
            case sensitivity exists.
            --
            Geoff Berrow 011000100110110 0010000000110
            001101101011011 001000110111101 100111001011
            100110001101101 111001011100111 010101101011

            Comment

            • Jeff

              #7
              Re: $_POST case sensitivity

              Bill H wrote:
              I wouldn't consider myself a newbie to PHP since I have never written
              one line of code in it (am a perl guy myself), but part of a team I am
              working with is writing some php interfaces into a database and I
              noticed that they are relaying on HTML form value names to always be
              lowercase in their code (ie $_POST['save'] (fyi that may be typed
              wrong)) and from my experience it is always better, when reading in
              the post information to convert the the form value name to uppercase
              on the off chance that one web page may have NAME="save" and another
              may have NAME="Save", this way you can will always get the value.
              >
              In perl this is easy cause you are pulling in the name / value pairs
              straight from the ENV value. But since, from what I see and they say,
              PHP does this for you and puts it into $_POST, is there a way to tell
              PHP to always convert the name of the value to uppercase?
              Not tested. My PHP is not great, but why not:

              foreach($_POST as $key){
              $_POST[strtoupper($key )]=$_POST[$key];
              }

              Jeff

              >
              Bill H

              Comment

              • larry@portcommodore.com

                #8
                Re: $_POST case sensitivity

                On Jul 6, 10:37 am, Jeff <jeff@spam_me_n ot.comwrote:
                Not tested. My PHP is not great, but why not:
                >
                foreach($_POST as $key){
                $_POST[strtoupper($key )]=$_POST[$key];
                >
                }
                >
                It would be more like:

                $strtoupper($_P OST[$key]) = $_POST[$key];

                If that doesn't work this will:

                $var = strtoupper($_PO ST[$key]);
                $$var = $_POST[$key];

                note: Always make sure you validate/filter any POST data that could
                lead to vulnerabilities .

                Comment

                • Jerry Stuckle

                  #9
                  Re: $_POST case sensitivity

                  Geoff Berrow wrote:
                  Message-ID: <poj074df5uogtc h41qe5ujc2ells5 8m1fv@4ax.comfr om Tim
                  Roberts contained the following:
                  >
                  >I find this philosophy interesting. Because these names ARE
                  >case-sensitive, I would consider it a programming error to use different
                  >spellings in different web pages.
                  >
                  >
                  Agreed but it may be sensible to allow for the possibility of the use of
                  incorrect case if the people preparing the html are not programmers.
                  Thanks to Bill Gates there are a lot of people who do not recognise that
                  case sensitivity exists.
                  Nope, just teach them the correct way to do it. It's never a good idea
                  to hide programming problems. They always come back to haunt you in the
                  end. And by that time they are much more expensive to fix than they
                  would have been if the job had been done right in the first place.

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • Bill H

                    #10
                    Re: $_POST case sensitivity

                    On Jul 6, 3:12 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                    Geoff Berrow wrote:
                    Message-ID: <poj074df5uogtc h41qe5ujc2ells5 8m...@4ax.comfr om Tim
                    Roberts contained the following:
                    >
                    I find this philosophy interesting.  Because these names ARE
                    case-sensitive, I would consider it a programming error to use different
                    spellings in different web pages.  
                    >
                    Agreed but it may be sensible to allow for the possibility of the use of
                    incorrect case if the people preparing the html are not programmers.
                    Thanks to Bill Gates there are a lot of people who do not recognise that
                    case sensitivity exists.
                    >
                    Nope, just teach them the correct way to do it.  It's never a good idea
                    to hide programming problems.  They always come back to haunt you in the
                    end.  And by that time they are much more expensive to fix than they
                    would have been if the job had been done right in the first place.
                    >
                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstuck...@attgl obal.net
                    =============== ===
                    Agreed they should always follow a set way, all form value names
                    uppercase (or lowercase), but you never know what someone may do
                    without thinking in the future. On the perl side, I try to always make
                    my form value names uppercase so they will always work with a cgi I
                    may have written awhile back, but by having this catch in there
                    (converting the key to uppercase) I never have to wonder if the form
                    valeu name is the reason why it somethign didn't work the way I
                    expected.

                    All the examples I have seen here (and thanks for them) all seem to be
                    making a 2nd entry in the $_POST array with the key value corrected to
                    uppercase. So am I correct in assuming you can't just tell PHP to do
                    it?

                    Bill H

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: $_POST case sensitivity

                      Bill H wrote:
                      On Jul 6, 3:12 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                      >Geoff Berrow wrote:
                      >>Message-ID: <poj074df5uogtc h41qe5ujc2ells5 8m...@4ax.comfr om Tim
                      >>Roberts contained the following:
                      >>>I find this philosophy interesting. Because these names ARE
                      >>>case-sensitive, I would consider it a programming error to use different
                      >>>spellings in different web pages.
                      >>Agreed but it may be sensible to allow for the possibility of the use of
                      >>incorrect case if the people preparing the html are not programmers.
                      >>Thanks to Bill Gates there are a lot of people who do not recognise that
                      >>case sensitivity exists.
                      >Nope, just teach them the correct way to do it. It's never a good idea
                      >to hide programming problems. They always come back to haunt you in the
                      >end. And by that time they are much more expensive to fix than they
                      >would have been if the job had been done right in the first place.
                      >>
                      >--
                      >============== ====
                      >Remove the "x" from my email address
                      >Jerry Stuckle
                      >JDS Computer Training Corp.
                      >jstuck...@attg lobal.net
                      >============== ====
                      >
                      Agreed they should always follow a set way, all form value names
                      uppercase (or lowercase), but you never know what someone may do
                      without thinking in the future. On the perl side, I try to always make
                      my form value names uppercase so they will always work with a cgi I
                      may have written awhile back, but by having this catch in there
                      (converting the key to uppercase) I never have to wonder if the form
                      valeu name is the reason why it somethign didn't work the way I
                      expected.
                      >
                      All the examples I have seen here (and thanks for them) all seem to be
                      making a 2nd entry in the $_POST array with the key value corrected to
                      uppercase. So am I correct in assuming you can't just tell PHP to do
                      it?
                      >
                      Bill H
                      >
                      No, PHP is case sensitive, just like HTML is. And that is the correct
                      way to do things.

                      You need standards on how to do things, and people need to follow those
                      standards. Otherwise, you have chaos. And if they do something else in
                      the future, the code breaks. That's simple.

                      But as an example as to why you shouldn't do it -

                      <input type=text name="NAME" ...>

                      Now what happens if later someone comes along with:

                      <input type=hidden name="name" ...>

                      In over 40 years of programming, I've seen things like this happen way
                      too many times because, rather than enforcing standards, someone tried
                      to cover up errors.

                      But when you set standards and enforce them, you have fewer errors in
                      the code, and find those errors earlier in the development process.

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • Paul Lautman

                        #12
                        Re: $_POST case sensitivity

                        macca wrote:
                        $_POST is just another array
                        >
                        foreach ($_POST as $key=>$value){
                        >
                        strtoupper($key );
                        >
                        }
                        I KNOW that! What the !¬"!££$£$ are you telling me for?

                        Learn how to post replies!


                        Comment

                        • macca

                          #13
                          Re: $_POST case sensitivity

                          blow me arse wipe.

                          Comment

                          • mike.coakley@gmail.com

                            #14
                            Re: $_POST case sensitivity

                            If all you are tying to do is uppercase (or lowercase - whatever) the
                            key names of an array you can use the PHP function
                            array_change_ke y_case.



                            It can change the values to upper or lower case depending upon the way
                            you call it. No need to build your own iterator.

                            So in your case: $_POST = array_change_ke y_case($_POST, CASE_UPPER);

                            BUT of course as someone else mentioned you should always NOT TRUST
                            input from the web so you should probably iterate over the $_POST
                            array anyway so do something like this:

                            $myPost = $_POST;
                            $_POST = array();
                            while (list($key, $value) = each($myPost)) {
                            $_POST[strtoupper($key )] = htmlentities($v alue);
                            }

                            Of course there are a million ways to to this and the htmlentities
                            (see http://us3.php.net/manual/en/function.htmlentities.php) might not
                            be how you want to handle input "cleansing" but this is a start.

                            Thanks,

                            Mike



                            Comment

                            • Bill H

                              #15
                              Re: $_POST case sensitivity

                              On Jul 6, 7:43 pm, mike.coak...@gm ail.com wrote:
                              If all you are tying to do is uppercase (or lowercase - whatever) the
                              key names of an array you can use the PHP function
                              array_change_ke y_case.
                              >

                              >
                              It can change the values to upper or lower case depending upon the way
                              you call it. No need to build your own iterator.
                              >
                              So in your case: $_POST = array_change_ke y_case($_POST, CASE_UPPER);
                              >
                              BUT of course as someone else mentioned you should always NOT TRUST
                              input from the web so you should probably iterate over the $_POST
                              array anyway so do something like this:
                              >
                              $myPost = $_POST;
                              $_POST = array();
                              while (list($key, $value) = each($myPost)) {
                                $_POST[strtoupper($key )] = htmlentities($v alue);
                              >
                              }
                              >
                              Of course there are a million ways to to this and the htmlentities
                              (seehttp://us3.php.net/manual/en/function.htmlen tities.php) might not
                              be how you want to handle input "cleansing" but this is a start.
                              >
                              Thanks,
                              >
                              Mike
                              Thanks Mike - this is what I am looking for. The problem I forsee and
                              am trying to avoid is after the database guys get done building their
                              php pages to interface with the database and the designers then take
                              over them in dreamweaver that they may mess form element names up
                              without realizing what they are doing since they don't no anythign
                              about programming, they just make the pages "pretty".

                              Bill H

                              Comment

                              Working...