music_lp90 Posted April 16, 2010 Share Posted April 16, 2010 Hi,I'm trying to add a feature to our CMS that would allow the admin to include a php file by using a trigger like this {~gallery|album=2~} "gallery" is the name of the php file and "album=2" is the required parameter, so the result would be include("www.url.com/includes/modules/gallery.php?album=2"). I can echo out that string, but I cannot include the file. I'm guessing that the include statement has already executed before the $include variable gets set. Is that correct? Any suggestions on how I might be able to accomplish what I'm trying to do?Here's the section of code for this: if(isset($_GET['id'])){ $content[0] = html_entity_decode($content[0]); $content[0] = stripslashes($content[0]); $find = '{~'; $findend = '~}'; $paramTrigger = '|'; if(strpos($content[0], $find) === false){ echo $content[0]; } else { if(!isset($_GET['edit'])){ // If edit is set, we only want to display the triggers, not the actual modules /* Find and insert Modules */ while(strpos($content[0], $find) !== false){ $pos = strpos($content[0], $find); // mark beginning of module tag $pos_end = strpos($content[0], $findend); // mark end of module tag $mod_start = $pos + 2; // mark beginning of module name for inserting in the include statement $mod_end = $pos_end - $pos - 2; // mark end of module name for including in the include statement $include = substr($content[0], $mod_start, $mod_end); if(strpos($include, $paramTrigger) === false){ $param = ""; } else { $fileInc = explode('|', $include); $include = $fileInc[0]; $param = '?' . $fileInc[1]; } $module = $g_url . "includes/modules/" . $include . ".php" . $param; // path to module if($pos > 0){ $content_start = substr($content[0], 0, $pos); // Get the content that can be echoed } $content[0] = substr($content[0], $pos_end + 2); if($pos > 0){ echo $content_start; } //echo '<p>' . $module . '</p>'; include($module); } } if ($content[0] > ""){ // echo the remaining content after the module was inserted echo $content[0]; } }} Thanks for your help! Link to comment Share on other sites More sharing options...
justsomeguy Posted April 16, 2010 Share Posted April 16, 2010 The include path shouldn't start with HTTP or a domain name, it should be a local filesystem path on the server, not a URL. You can get the full path to the current script with dirname(__FILE__). You may have a problem passing parameters through $_GET to an include file, but you can always use a global variable to hold parameters that the include file would check. Link to comment Share on other sites More sharing options...
music_lp90 Posted April 16, 2010 Author Share Posted April 16, 2010 The include path shouldn't start with HTTP or a domain name, it should be a local filesystem path on the server, not a URL. You can get the full path to the current script with dirname(__FILE__). You may have a problem passing parameters through $_GET to an include file, but you can always use a global variable to hold parameters that the include file would check.Thanks JSG, I thought I had seen somewhere that the way to pass parameters to an included file was to use http, but if it works at all, I guess it doesn't work very well and most hosts wouldn't allow it from what I just looked up.I ran a quick test to see what happens when trying to include with http and got these errors:"URL file-access is disabled in the server configuration" and "failed to open stream: no suitable wrapper could be found"Thanks for your help! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.