dropbop Posted August 1, 2011 Share Posted August 1, 2011 Is there a way to include a file using a define. I am using zencart and it has text defined when a person is not logged in, but I would like to place something more than just text. The define from the language file is: if (STORE_STATUS == '0') { define('TEXT_GREETING_GUEST', 'Welcome new customer'); } else { define('TEXT_GREETING_GUEST', 'Welcome, please enjoy our online showcase.'); } define('TEXT_GREETING_PERSONAL', 'Hello <span class="greetUser">%s</span>! Would you like to see our <a href="%s">newest additions</a>?'); I have a php file with a set of jquery tabs and the info pulled from the database for each tab. This is for people not logged in or approved to shop which would go here: define('TEXT_GREETING_GUEST', 'notloggedin.php'); I then have another file I would like to include when a customer has created an account and logged in which would go here: define('TEXT_GREETING_PERSONAL', 'loggedin.php'); Here is the code from the file to include when not logged in (have not created the 'logged in' file yet) <?php require_once ('includes/configure.php'); $tabtitles = ""; $tabcontents = ""; $sqloo = mysql_query("SELECT * FROM front_page_tabs ORDER BY tab_id ASC"); $tabCount = mysql_num_rows($sqloo); // count the output amount if ($tabCount > 0) { while($row = mysql_fetch_array($sqloo)){ $id = $row["tab_id"]; $tabtitle = $row["tab_title"]; $tabcontent = $row["tab_content"]; $tabtitles .= ' <li><a href="#tab' . $id . '">' . $tabtitle . '</a></li>'; $tabcontents .= ' <div id="tab' . $id . '" class="tab_content">' . $tabcontent . '</div> '; } } else { $dynamicList = "Please add a Tab Title"; } #mysql_close(); ?> <ul class="tabs"> <?php echo $tabtitles; ?> </ul> <div class="tab_container"> <?php echo $tabcontents; ?> </div> So what I need to know is can a file be included in a php define. I have tried several ways but nothing is working for me. Cheers, Eoin Quote Link to comment https://forums.phpfreaks.com/topic/243459-possible-to-include-files-using-define/ Share on other sites More sharing options...
trq Posted August 1, 2011 Share Posted August 1, 2011 You could place the file in a variable and then use that. Quote Link to comment https://forums.phpfreaks.com/topic/243459-possible-to-include-files-using-define/#findComment-1250120 Share on other sites More sharing options...
dropbop Posted August 1, 2011 Author Share Posted August 1, 2011 Hi thorpe, Thanks for the reply. You could place the file in a variable and then use that. Thats actually what i have been trying, but don't think im doing it right, this is what I have (one of many attempts).. $mainpagetabs = file_get_contents('/tabs/frontpagetabs.php'); define('TEXT_GREETING_GUEST', $mainpagetabs); I have tried a few different ways using single and double quote too. I think I still have a bit to learn Eoin Quote Link to comment https://forums.phpfreaks.com/topic/243459-possible-to-include-files-using-define/#findComment-1250139 Share on other sites More sharing options...
trq Posted August 1, 2011 Share Posted August 1, 2011 If the file you want to include has php that needs to be processed file_get_contents() won't help. You would need your own function for this. function include_as_string($file) { ob_start(); include $file; return ob_get_contents(); } Quote Link to comment https://forums.phpfreaks.com/topic/243459-possible-to-include-files-using-define/#findComment-1250143 Share on other sites More sharing options...
dropbop Posted August 1, 2011 Author Share Posted August 1, 2011 If the file you want to include has php that needs to be processed file_get_contents() won't help. You would need your own function for this. function include_as_string($file) { ob_start(); include $file; return ob_get_contents(); } Im having no luck with this at all.. I cant seem to pull the file in no matter what I try. Almost every out put is either the filename or else blank. Thanks anyway for the help thorpe, but I don't think i'm fully understanding how its done. I have been over at stackoverflow, php.net and a few other places, but there are so many different answers and explanations that I am totally confused now. There must be a simple way to plonk a php file into a define and call it on a page. If it helps, here is my php & mysql versions MySQL: 5.5.8 PHP Version: 5.3.5 Eoin Quote Link to comment https://forums.phpfreaks.com/topic/243459-possible-to-include-files-using-define/#findComment-1250172 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.