Bluehost.com Web Hosting $6.95

$_POST case sensitivity

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 (...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-05-2008
Bill H
 
Posts: n/a
Default $_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
Reply With Quote
  #2 (permalink)  
Old 07-05-2008
Paul Lautman
 
Posts: n/a
Default 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.


Reply With Quote
  #3 (permalink)  
Old 07-06-2008
macca
 
Posts: n/a
Default Re: $_POST case sensitivity

$_POST is just another array

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

strtoupper($key);

}
Reply With Quote
  #4 (permalink)  
Old 07-06-2008
Tim Roberts
 
Posts: n/a
Default 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 "<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.
Reply With Quote
  #5 (permalink)  
Old 07-06-2008
The Natural Philosopher
 
Posts: n/a
Default 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 "<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.
Reply With Quote
  #6 (permalink)  
Old 07-06-2008
Geoff Berrow
 
Posts: n/a
Default Re: $_POST case sensitivity

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
Reply With Quote
  #7 (permalink)  
Old 07-06-2008
Jeff
 
Posts: n/a
Default 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

Reply With Quote
  #8 (permalink)  
Old 07-06-2008
larry@portcommodore.com
 
Posts: n/a
Default Re: $_POST case sensitivity

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.
Reply With Quote
  #9 (permalink)  
Old 07-06-2008
Jerry Stuckle
 
Posts: n/a
Default Re: $_POST case sensitivity

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
==================

Reply With Quote
  #10 (permalink)  
Old 07-06-2008
Bill H
 
Posts: n/a
Default Re: $_POST case sensitivity

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:19 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0