| dynamic php includes in smarty templates -
25-04-2007, 06:33 AM
There is a serious issue with this SmartyLight or TemplateLight class included in the eSupport system. I cannot get a php include to work on any files that also include other files. When I try, the page just ends up blank, and no errors are reported on the site or in the logs (yes my error reporting is on). The only time I've seen this happen before was with memory leaks or required files are missing.
The only thing that worked was to do a full remote path include like this:
include("http://www.example.com/include_file.php");
But unfortunately that method doesn't allow you to use any of the global variables set for the rest of the site, even if it is still under the same domain.... I think because it's routed through a different port and has a different referrer variable set, but that's just a guess. I've been struggling with trying to access the global $_COOKIE variables from the include, but none of the $_GET, $_POST, or $_REQUEST variables will output either.
Also it is a huge security hole. In order for that method to work, you have to set allow_url_include = On in your php.ini file. This opens up your site to anyone to run your code. Not good. So for debugging sake, I've tried all of these methods in the header template: TemplateLite Import Methods { include file="../include_file.php" } // doesn't process php
{php} include("../include_file.php"; {/php} // doesn't process php
and other variations of the 2 methods including include_php and varioius attempts at bracket positions PHP Import Methods include("../include_file.php"); // returns blank page - this method should work always
include("support_top.php"); // returns blank page $url = $_SERVER['HTTP_HOST'] . "/include_file.php"; include($url); // returns page but no global variables accessible
$filename = $_SERVER["DOCUMENT_ROOT"] . "/include_file.php"; include($filename); // returns blank page ob_start(); $filename = $_SERVER["DOCUMENT_ROOT"] . "/include_file.php"; include($filename);
$inc = ob_get_contents();
ob_end_clean();
echo $inc; // returns blank page I've also tried modifying the class.compiler.php and class.template.php scripts to stop caching, but that didn't help and I reverted back to the original files.
My memory_limit settings are set to infinite in my php.ini, so a memory leak isn't the problem. I've even modified it to stop at 8 or 12mb but that didn't help.
So basically I've tried every method in the book for simply importing a local php file into the smarty template, and nothing works correctly. My guess is there's something wrong with the way the Smarty compiler is trying to read or eval include files or else there's something wrong with how it's handling cached files in relation to include files within include files. NOTE: The regular php include function does work, but not if the included file contains any other includes. I'm using an include in the footer template just fine but the included file only contains php code and html without any other includes being called.
If anyone can shed some light on this issue I'd really appreciate it. If I can't get this to work soon, then I'm not going to use this system. Hopefully all of the methods I've described above will help the developers realize what the problem is quickly.
Last edited by ebyte.com; 25-04-2007 at 06:42 AM.
|