Re: Good morning!!!!!!

From: Date: Tue, 16 Oct 2001 13:39:58 +0000
Subject: Re: Good morning!!!!!!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-71207@lists.php.net to get a copy of this message
On Tue, 16 Oct 2001, Balaji Ankem wrote: > > > > Hi! friend, > see the following..what will be the output?? > > Here i am calling example.php in php file after starting a session.. > > example.php > ------------------ > <?php > > > if (!isset($HTTP_SESSION_VARS["user"]) && > !isset($HTTP_SESSION_VARS["pw"])) > { > > header("Location:secure.php"); > > } > > ?> > ----------------------- > > secure.php > ------------------------------ > <?php > > require("secure_connection.php"); // required function is in this file > > session_authentication(); file://function call > > ?> > ------------------------------ > > secure_connection.php > --------------------------------- > <?php > > function session_authentication() > { > > session_start(); > > if (!isset($HTTP_SESSION_VARS["user"]) && > !isset($HTTP_SESSION_VARS["pw"])) > { > > session_destroy(); > echo "Bad I am not expecting this output"; > } > > else > { > echo "good expected output"; > } > } > > ?> > ------------------------------------ > > I am expecting "good expected output"..but itz displaying the otherone.(Bad > i am not expecting this output). > > Instead of function call if i execute the code which is written in the > function then itz displaying the "good expected output".. > > what z wrong with me?? > > Thanks and regards > -Balaji > > > > > > > > I have run into a similar problem in the past. The way that I fixed it was to pass $HTTP_SESSION_VARS to the function in one of two ways. (1) Pass the array as part of the function call: session_authentication($HTTP_SESSION_VARS); function session_authentication($HTTP_SESSION_VARS) { // Function Code... } (2) Pass the array as a global variable: function session_authentication() { global $HTTP_SESSION_VARS; // Function Code... } Personally, I like example #2 better. IMHO, I think that this keeps the code cleaner, and keeps me from having to remember which variables need to be passed to the function in what order. Hope this helps, Chesley

« previous php.general (#71207) next »