Hello there,
I have a script which generates a dynamic side menu for my site, that I require() into the pages of the site I'm working on (so its easy to edit). I include this using an url wrapper so that i can use the $GET query string.
Ex:
require "http://".$_SERVER['HTTP_HOST']."/static/sideMenus.php?m1&mA&login";
OR
require "http://".$_SERVER['HTTP_HOST']."/static/sideMenus.php?m1&m2&m3";
However, I need to have the script inherit the parent file's variable scope. But because of this:
(from the manual)If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see List of Supported Protocols/Wrappers for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.
That cannot happen. This is important due to the structure of the included file (see below), because I need to use the current instance of the $session object. Is there a work-around for this, or another way to do this so that I can use the query string AND the current variable scope is maintained? Any help is greatly appreciated. Thanks!
sideMenus.php:
<?php
//doing this to try to get the curr var scope DOES NOT WORK, b/c i only creats a new instance,
//instead of working off the current instance.
//include_once "../app/include/session.php";
echo "
<div class=\"sidenav\">\n";
if(isset($_GET['m1'])){
echo "
<h1>Essentials</h1>
<ul>
<li><a href=\"index.php\">Permission Form</a></li>
<li><a href=\"index.php\">Medical Form</a></li>
<li><a href=\"/get.php?directions\">Directions</a></li>
<li><a href=\"index.php\">What To Bring</a></li>
</ul>\n";
}
if(isset($_GET['m2'])){
echo "
<h1>Logistics</h1>
<ul>
<li><a href=\"index.php\">Schedule of Events</a></li>
<li><a href=\"index.php\">Schedule of Training</a></li>
<li><a href=\"index.php\">semper</a></li>
<li><a href=\"index.php\">sociis natoque</a></li>
</ul>\n";
}
if(isset($_GET['m3'])){
echo "
<h1>Third and last</h1>
<ul>
<li><a href=\"index.php\">sociis natoque</a></li>
<li><a href=\"index.php\">magna sed purus</a></li>
<li><a href=\"index.php\">tincidunt</a></li>
<li><a href=\"index.php\">consequat molestie</a></li>
</ul>\n";
}
if(isset($_GET['mA']) && ($session->userlevel > 6)){
echo "
<h1>Admin Controls</h1>
<ul>
<li><a href=\"/staff/pending.php\">Manage Pending Staff</a></li>
<li><a href=\"/staff/viewStaff.php\">View All Staff</a></li>
<li><a href=\"/staff/viewComms.php\">View Committees</a></li>
<li><a href=\"index.php\">consequat molestie</a></li>
</ul>\n";
}
if(isset($_GET['login']) && !$session->logged_in){
echo "
<h1><a href='/app/login.php' >Staff Login</a></h1>
<form name=\"login\" id=\"login\" method=\"post\" action=\"../app/process.php\" >";
if($form->num_errors > 0){
echo "errors found!";
}
echo "
<fieldset>
<label for=\"user\">Username:</label>
<input type=\"text\" name=\"user\" style=\"margin:1px;\" /><br />
<label for=\"pass\">Password:</label>
<input type=\"password\" name=\"pass\" style=\"margin:1px;\" />
<input type=\"hidden\" name=\"sublogin\" value=\"1\" />
<input type=\"submit\" value=\"Login\" />
</fieldset>
</form>
\n";
}
echo " </div>\n";
?>