PHP accessing variables problem on require() function
<p>I have a question about PHP <code>require()</code> function. I have a PHP script called (<code>login.php</code>) and on that (login.php) I use various <code>require()</code> functions to get heavy PHP coded scripts to work on that original script (<code>login.php</code>).</p>

<p>However I noticed on a <code>require()</code> script I can access local variables defined on the original (login.php). However the problem is say on that required script I have another <code>require()</code> function then those variables originally defined on (<code>login.php</code>) are lost (ie if I do an <code>isset()</code> says they are not set?). So how do you get around this <code>require()</code> within <code>require()</code> problem?</p>

<p>Any ideas perhaps using <code>$_SESSION</code> or <code>$GLOBALS</code> variables instead? I know about <code>$_SESSION</code> variables but are <code>$GLOBALS</code> variables secure? </p>

<p>Below is short example of script var set on (login.php)</p>

<pre><code>if(!isset($header_displayed))
    {
        echo "&lt;div id='header'&gt;
            &lt;div id='logo'&gt;&lt;/div&gt;
        &lt;/div&gt;";
        $header_displayed=1; 
    }
</code></pre>

<p>Then this script is called from above (login.php) using require()</p>

<pre><code>if(!function_exists('writeErrors'))
    {
        function writeErrors($error,$host_details,$date,$page,$line) 
        {
            require("/home/darren/crash_msg/error_msg.php");
        }
    }
</code></pre>

<p>And then on error_msg script called the $header_displayed var is not set?</p>

<p>From feedback seems using require() within function will restrict all global vars. So you have to do this:</p>

<pre><code>    if(!function_exists('writeErrors'))
    {
        function writeErrors($error,$host_details,$date,$page,$line, add var paramters that you need ie $header_displayed) 
        {
            /*log SQL stuff*/
            $display_error_msg=1;
require("/home/darren/crash_msg/error_msg.php"); /*now header_displayed var set on this script*/
        }
    }
</code></pre>
