Fellow Coders,
I'm running into some trouble... I've been working on a site lately as a pet project, and I've decided to eliminate as much of the HTML from my PHP scripts as possible. I am, instead, placing it in a file, and eval()'ing the contents of the file. My problem is that when running the eval() on the file - which is actually just the contents returned into a string, the session variables are always returning as $NULL. Any ideas? Code follows, incase there's some sort of logic error...
login.php----
<?PHP
//Contains my DB Classes
require("scripts/mysql_db.inc");
//Contains my site's user classes
require("scripts/ddisg_user.inc");
//contains generic code
require("scripts/basic.inc");
//Make sure the session is active
session_start();
//initialize DB
$ddisg_db = new cls_mysql_db();
$ddisg_db->open_db('localhost','username','password','dbname');
//if the user is not logged in, or his user
data is not set, write out the data for a user to register.
if ((!isset($logged_in)) || (!isset($my_userdata))) {
WriteOutFile("templates/loginr.tpi");
exit;
}
//otherwise, the user is logged in, and we can write out the file for registered users.
else {
WriteOutFile("templates/logind.tpi");
}
?>
basic.inc----
//this is the file that was referenced previously by the require("scripts/basic.inc"); line
<?PHP
//we may or may not need this here, but why take chances?
session_start();
function WriteOutFile($filename) {
$flen = filesize($filename);
if (!$file=fopen($filename, "r")) {
//to be replaced by calls to site_error(); when debugging is complete here.
echo 'failed to open template: ' . $filename;
echo 'The site admin has been notified';
echo 'This is error number 150: no template available';
}
else {
$str = fread($file,$flen);
eval ("session_start(); ?> $str");
fclose($file);
}
echo $str;
}
?>
logind.tpi--- the problem child
<?PHP
//I'm not sure about this, since I don't know if the session_start() from basic.inc will initialize this file properly.
session_start();
?>
<HEAD>
<TITLE>DeVry Dallas Independent Study Groups (DeDISGee) - Logged in as <?PHP echo $my_userdata["username"]; ?></TITLE>
</HEAD>
<FRAMESET border=0 frameBorder=0 frameSpacing=0 rows=89,,87 framepadding="0">
<FRAME name="header" marginHeight=0 marginWidth=0 name=header noResize scrolling=no src="liheader.php" topmargin="0" leftmargin="0">
<FRAMESET border=0 cols=15%, frameBorder=0 frameSpacing=0 framepadding="0">
<FRAME name="leftside" marginHeight=0 marginWidth=0 name=main noResize scrolling=no src="selections.php" topmargin="0" leftmargin="0">
<FRAME name="rightside" marginHeight=0 marginWidth=0 name=body noResize src="body.php" topmargin="0" leftmargin="0">
</FRAMESET>
<FRAME name="footer" marginHeight=0 marginWidth=0 name=footer noResize scrolling=no src="lifooter.php" topmargin="0" leftmargin="0">
</FRAMESET>
Anyway, I think this should give a fairly complete picture. I'm stumped, and have been since tuesday. I've continued to develop other areas of the site, but this is leaving me in the dark. Any help would be appreciated.
Thanks in advance,
Stephen