Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] php help passing variables

On Wed, 2002-10-23 at 15:33, Amanda Wynne wrote:

There's an option - register_globals I think it's called. It's turned
off by default in php's since 4.2 I think. (somewhere in the 4 series
anyway). It's because it was a security hole, I kinda agree with the
decision though it's forced me to fix up a whole lot of old code
(because of course, all the literature about php recommends this method)

The registered globals have been replaced with these "special" variables
- $_GET and $_POST. The trouble is that they didn't exist on previous
php's. So, you have the choice of either breaking compatability with old
versions, using the deprecated functionality and enabling the
appropriate options in php.ini to make it work, or writing a dodgy
wrapper function like this:

/** Version independent way to retrieve get vars
 *  @param  name    the name of the get var to retrieve.
function get_var ($name = -1) {
    if ($name == -1) {
        if (isset ($_GET)) {
            return $_GET;
        } else {
            return @$GLOBALS['HTTP_GET_VARS'];
    if (isset ($_GET[$name])) {
        return $_GET[$name];
    } else {
        return @$GLOBALS['HTTP_GET_VARS'][$name];

There was a reason I used -1 there instead of null... I can't remember
what it was. It could have been that older php's didn't have nulls, but
I don't remember. It's probably safe to change the default to NULL and
replace the name test with "is_null ($name)" at least on php newer than
4.0... Not that I see people calling their get vars "-1" all that often.

I don't know how on-topic php is for slug. Might be better to pursue php
stuff in -chat and CC me.