I Need to update outdated method

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

I Need to update outdated method

Post by someguyhere »

I am using the following code in a form:

Code: Select all

function pt_register(){

  $num_args = func_num_args();
   $vars = array();

   if ($num_args >= 2) {
       $method = strtoupper(func_get_arg(0));

       if (($method != 'SESSION') && ($method != 'GET') && ($method != 'POST') && ($method != 'SERVER') && ($method != 'COOKIE') && ($method != 'ENV')) {
           die('The first argument of pt_register must be one of the following: GET, POST, SESSION, SERVER, COOKIE, or ENV');
     }

       $varname = "HTTP_{$method}_VARS";
      global ${$varname};

       for ($i = 1; $i < $num_args; $i++) {
           $parameter = func_get_arg($i);

           if (isset(${$varname}[$parameter])) {
               global $$parameter;
               $$parameter = ${$varname}[$parameter];
          }

       }

   } else {
       die();
   }

}
and then a bit later, this:

Code: Select all

pt_register('POST','key_word');

   if ($_SERVER['REQUEST_METHOD'] != 'POST'){

Followed by a bunch of other stuff (php & html).

Basically, I have a page that contains a form. When you fill in the field and hit submit, it processes the data and then presents some info on the same page. I was doing a bit of research to fix another issue (I need the script not to pass header info since it's part of a plugin for Wordpress) and found that this method is outdated. Can someone point me to a better method?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: I Need to update outdated method

Post by Weirdan »

Why do you need anything from request/environment in the global scope?
Post Reply