PHP newbieness (was Re: [prog] Introducing . . . )

Katie Bechtold katie at katie-and-rob.org
Tue Nov 5 15:44:08 EST 2002


On Tue, Nov 05, 2002 at 01:20:38PM -0600, abbey wrote:
> My goal is to learn enough linux/php/mysql to get some web pages coded and 
> maybe support my internet habit of learning a little more tomorrow.

Hi Tamara!  (I'm fighting the urge to call you abbey because that's
what you e-mail's From line calls you.)

I'm also a PHP newbie, and I feel compelled to share this tidbit of
knowledge in the hopes that it will save other PHP newbies some
headaches.  It is this: starting with PHP version 4.2.0, there is a
big change having to do with superglobal variables.  Before getting
into it, I want to note that this change will break scripts written
for prior versions of PHP if you're running them on version 4.2.0 or
later.*

If you're using PHP to write web scripts, superglobals are
predefined arrays containing variables from the web server, the
environment, and user input.  Whereas in older version of PHP you
might refer to a variable like $php_auth_user, in newer versions you 
will use something like $_SERVER['PHP_AUTH_USER'].  Likewise, where
before you might have written $favourite_colour to access a user's
input to a form field, you'd now use $_GET['favourite_colour'] or
$_POST['favourite_color']. 

The bottom line is, if you're web scripting with PHP, it's really
important to know which version of PHP you're running.  For more on
superglobals, see
http://www.php.net/manual/en/language.variables.predefined.php#language.variables.superglobals.



* Unless you explicitly turn on the PHP directive register_globals
(in php.ini), but the PHP Manual recommends against doing that 
because security is generally tighter if you leave it to the default 
value of off.  (In versions prior to 4.2.0, the default value is
on.)

-- 
Katie Bechtold
http://katie-and-rob.org/




More information about the Programming mailing list