jonshutt Posted July 27, 2009 Share Posted July 27, 2009 Hi all, not sure if this is posible, but.. I've recently been taking a large website, and putting the page content into a mysql database so it can be worked on in a CMS. However, some of the pages have PHP scripts within the content on the page - (mainly php includes). So, when I run my template, and load the page content out of the database and write it back on to the page, php just reads the info from the field and writes it onto the page, but of course, it doesn't execute the php script. Does anyone know any way around this? maybe getting php to check through the data and run any commands it finds? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/167693-getting-content-with-php-includes-from-a-database/ Share on other sites More sharing options...
jonshutt Posted July 27, 2009 Author Share Posted July 27, 2009 for example, $string = "will this work: <? print 'yes'; ?>"; print $string; this will print "will this work: <? print 'yes'; ?>" whereas I need it run the command and print "will this work: yes" thanks Quote Link to comment https://forums.phpfreaks.com/topic/167693-getting-content-with-php-includes-from-a-database/#findComment-884363 Share on other sites More sharing options...
aschk Posted July 28, 2009 Share Posted July 28, 2009 Use include instead of echo/print, I believe this should resolve your problem. Quote Link to comment https://forums.phpfreaks.com/topic/167693-getting-content-with-php-includes-from-a-database/#findComment-884977 Share on other sites More sharing options...
PFMaBiSmAd Posted July 28, 2009 Share Posted July 28, 2009 The C in CMS stands for Content, not Code. As a general rule, code should not be stored in with content as that opens up a huge window for abuse (a hacker just needs to get his php code into your content in order to take over your site.) You should not store php code in your content and if you do find that you need to do something like put logic into your content, you should be using a template system, instead of directly executing content/code in a string using an eval() statement, so that you will have control over what exactly can be put into it. Quote Link to comment https://forums.phpfreaks.com/topic/167693-getting-content-with-php-includes-from-a-database/#findComment-885184 Share on other sites More sharing options...
jonshutt Posted July 29, 2009 Author Share Posted July 29, 2009 hmm, I understand the theory of not putting code in the database. However, I'll give you an example of why I might need to. The CMS stores the html for area on the page (within a template). Some of these areas include a PHP script like <? include 'video.php'; ?> which should bring in a file with a video player in it. Having the video.php file as an include file make sense, as it's used many times. To avoid having the code in the database, i would have to write the entire content of the video.php file into all the places it is used - losing the ability to update it quickly. Unless anyone has any suggestions on how to do the equivilent of an include but not using PHP? (Server side includes don't seem to work on a php file) I know it all sounds very muddled, but i'm updating an old website, - if I was building from fresh it's not how i'd do it! Quote Link to comment https://forums.phpfreaks.com/topic/167693-getting-content-with-php-includes-from-a-database/#findComment-885633 Share on other sites More sharing options...
aschk Posted July 29, 2009 Share Posted July 29, 2009 Use an include to include video.php in your other templates. And for editing the file, just open the file using php file functions (fopen, fread, fwrite, fclose, etc), instead of loading a database field into your textarea. It's just the same really. Wordpress does it Quote Link to comment https://forums.phpfreaks.com/topic/167693-getting-content-with-php-includes-from-a-database/#findComment-885914 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.