Functions

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

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

dibyendrah wrote:Inside the function, unless you pass the variable as argument, other variable cannot be accessed unless you call global variable. So, you better call the global POST, GET variable by writing the statement :

Code: Select all

global $HTTP_POST_VARS;
will solve your problem.

Code: Select all

function validateInput(){
    global $HTTP_POST_VARS;
    if(empty($HTTP_POST_VARS['fname'])){
        return false;
    }else{
        return true;
    }
}
With Regards,
Dibyendra
Long arrays are deprecated. In PHP3 and PHP4, if you wanted to use them inside a function you had to gloablize them, but in in PHP4 and PHP5 the short arrays are super globals and do not need to be globalized (as they are already gloabl). So in a nutshell:
  • Use $_GET not $HTTP_GET_VARS
  • Use $_POST not $HTTP_POST_VARS
  • Use $_COOKIE not $HTTP_COOKIE_VARS
  • Use $_SESSION not $HTTP_SESSION_VARS
  • Use $_SERVER not $HTTP_SERVER_VARS
  • Use $_ENV not $HTTP_ENV_VARS
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Thanks for the information. It has been a habit doing in the same old style.

Regards,
Dibyendra
Post Reply