mgarant Posted March 8, 2011 Share Posted March 8, 2011 Hello all, I'm a brand new user of this forum, and made a little search about my problem before posting, but couldn't find any straight-forward answer to my question... So here i am! What I'm trying to do is to include all my php files dynamically.... (I do the same for JS and CSS files and it is working great) Let me explain... I run a php script that start from the root of the web site and iterate through all the folder and subfolders and returns all the files contained in the web site directory. Everything is working fine for that. What i don't know how to do is generate all my php includes from that script. For the JS and CSS it is quite easy... juste generate a big string containing the all <script> tags... same goes for CSS... but for php, I have no idea how I could transfer my includes from the script to the page calling the script. Here is a code sample <?php include("path/class.websitehelper.php"); $Websitehelper = new Websitehelper(); $includes = $Websitehelper->GenerateIncludes(); //To use/plug the JS scripts echo $includes['JS']; //To use/plug the CSS echo $includes['CSS']; //How do i plug the php includes????? ?> Anyone have any idea? Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/230023-auto-generate-multiple-includes/ Share on other sites More sharing options...
taquitosensei Posted March 8, 2011 Share Posted March 8, 2011 have a php page with all your includes then include that page at the top of each page that needs them phpincludes.php include('page1.php'); include('page2.php'); include('page2.php'); // etc then include('phpincludes.php'); Quote Link to comment https://forums.phpfreaks.com/topic/230023-auto-generate-multiple-includes/#findComment-1184696 Share on other sites More sharing options...
mgarant Posted March 8, 2011 Author Share Posted March 8, 2011 Thanks for the quick reply taquitosensei ! That is what i am actually doing, but it can be a real pain in the ass to do this when you have like 100 php files... And when you add one, or change the name of one file... it is a pain as well to change it... That is why I want to generate these includes dynamically by iterating through all the files in the website directory... Any other ideas on how I could achieve this? Quote Link to comment https://forums.phpfreaks.com/topic/230023-auto-generate-multiple-includes/#findComment-1184726 Share on other sites More sharing options...
taquitosensei Posted March 8, 2011 Share Posted March 8, 2011 You don't change the name of the include file. That way all you have to do is edit the single include file to add/edit/remove an include. Plus auto including files in a folder could be a big security risk. Quote Link to comment https://forums.phpfreaks.com/topic/230023-auto-generate-multiple-includes/#findComment-1184739 Share on other sites More sharing options...
Mahngiel Posted March 9, 2011 Share Posted March 9, 2011 if you're going to include all of your php's, you may as well just combine them into one, well deliminated, well commented php file. Quote Link to comment https://forums.phpfreaks.com/topic/230023-auto-generate-multiple-includes/#findComment-1184834 Share on other sites More sharing options...
trq Posted March 9, 2011 Share Posted March 9, 2011 Take a look at http://php.net/__autoload Quote Link to comment https://forums.phpfreaks.com/topic/230023-auto-generate-multiple-includes/#findComment-1184849 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.