Whilst I have read some responses to the same question in other forums, I still do not understand this. All I want to so is call a function and declare a session variable in that function which is available in the calling code. I have file1.php which has session_start and then file2.php is included into this file. A function is called from within file2.php and the session variable needs to be available in file1.php. I have session_start(); in file2.php too. I am sure that this is fair easy, just not clicked with me yet. Thanks
You can't do more than one session_start in many file, an easy way to prevent this to apen is to set a $_SESSION var after session start and check if exist if (!isset($_SESSION['open_session'])) { session_start(); $_SESSION['open_session'] = 'yep'; } PHP: For your other bug how to retreive info from file2.php in file1.php in use fonction juste return the info you need in your function. In file1.php $receive_var = function_in_file2(....); In file2.php function function_in_file2(...) { return $var;}
I think SESSION thing is a global stuff so it doesn't matter inside or out side functions, but what u do with it will affect to this variable by the order of the code which is executed logically. the function session_id() may be able help if you aren't sure whether your session is already there or not. here you can surf for more info: http://www.php.net/manual/en/function.session-id.php
The session is not dependent on any function as it is globally defined.Although if it is possible to call any session through function call, I am also interested to know about it.