pthurmond Posted November 11, 2006 Share Posted November 11, 2006 Ok a couple of function questions.First, can a function you call access the $_POST array within it, without passing it?Second, when dealing with functions that need to connect to the database or use session info do I need to do the includes and session start inside each function in a file containing multiple functions, or can I just declare those at the top of the file outside the functions and be good.Examples:Option 1-[code]require_once('connecttodb.php'); //Connect to the dbsession_start();function dosomething(){}function dosomethingelse($val){}[/code]Option 2 - [code]function dosomething(){ require_once('connecttodb.php'); //Connect to the db session_start();}function dosomethingelse($val){ require_once('connecttodb.php'); //Connect to the db session_start();}[/code]Thanks for your help,-Patrick Link to comment https://forums.phpfreaks.com/topic/26960-functions-functions-and-more-functions/ Share on other sites More sharing options...
toplay Posted November 11, 2006 Share Posted November 11, 2006 1) The $_POST is a superglobal array variable so you don't have to pass it to each function.2) Issue just one session_start() at the beginning (before you send any output to the browser). So Option 1 is the correct approach, although I recommend putting it even before the require_once().http://us3.php.net/manual/en/reserved.variables.php#reserved.variables.posthttp://us3.php.net/manual/en/function.session-start.php Link to comment https://forums.phpfreaks.com/topic/26960-functions-functions-and-more-functions/#findComment-123271 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.