This is a discussion on $_POST case sensitivity within the PHP Language forums, part of the PHP Programming Forums category; I wouldn't consider myself a newbie to PHP since I have never written one line of code in it (...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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 "<input> field 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. |
|
|||
|
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 "<input> field 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. |
|
|||
|
Message-ID: <poj074df5uogtch41qe5ujc2ells58m1fv@4ax.com> from 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 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 |
|
|||
|
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 |
|
|||
|
On Jul 6, 10:37 am, Jeff <jeff@spam_me_not.com> wrote:
> 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($_POST[$key]) = $_POST[$key]; If that doesn't work this will: $var = strtoupper($_POST[$key]); $$var = $_POST[$key]; note: Always make sure you validate/filter any POST data that could lead to vulnerabilities. |
|
|||
|
Geoff Berrow wrote:
> Message-ID: <poj074df5uogtch41qe5ujc2ells58m1fv@4ax.com> from 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@attglobal.net ================== |
|
|||
|
On Jul 6, 3:12*pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Geoff Berrow wrote: > > Message-ID: <poj074df5uogtch41qe5ujc2ells58m...@4ax.com> from 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...@attglobal.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 |