At 18:52 06.11.2002, Jason Young spoke out and said:
>I (think I) have come up with an interesting little solution for pages 
>that have/can potentially have a lot of get vars, and I just wanted to 
>throw it by everyone to see if I know what I'm talking about...
>Instead of having a whole bunch of ...
>"if (isset($_GET['var']))
>  $var = $_GET['var']"
>.. lines on top of each page.. does this code look feasable to you?
>$get_allow = array('foo', 'bar', 'add', 'takeovertheworld');
>while (list($key,$val)=each($get_allow))
>   if (isset($_GET[$key]))
>     $$key = $val;

You're doing this to filter out parameters, and to emulate
register_globals, right?

To allow only a specific set of variables for $_GET, this loop may present
an elegant solution:
        foreach ($_GET as $name => $value) {
                if (!in_array(strtolower($name), $get_allow))
Note that I'm using "strtolower" for array lookup.

Ever had a headache with posted parameters, as to where to look for the
value, in _GET or _POST? Try this:
        foreach ($_POST as $name => $value)
                $_GET[$name] =& $value;
Your application may safely use only the $_GET array after this, the POSTed
variables correctly overriding their GET counterparts. The "=&" reference
is there for optimization - faster and less memory-consuming.

Wnat to have these global after all?
        foreach ($_GET as $name => $value) {
                global $$name;
                $$name =& $value;

Have fun,

   >O Ernest E. Vogelsinger 
   (\) ICQ #13394035 

Reply via email to