Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTed Sumner
Courses Plus Student 17,967 PointsPHP require_once issue
I just successfully troubleshot an issue I had with my PHP code to having nested require_once commands and am wondering the proper way to handle this issue. This is the file structure:
Index calls header and footer php files. header.php calls head.php and nav.php. When all of the files have require_once code for my global variable config.php file, index does not display.
Each of the files need the global variables in order to properly link. Can I call the config file in the index and have it trickle down to the nested files? I have changed the code to include, but I think I recall from the video that require_once is a better code choice for global variables.
1 Answer
Chris Shaw
26,676 PointsHi Ted,
Yes, that is 100% possible. All you need to do is require
your config file before your header file and the variables will be passed along as PHP executes scripts from top-to-bottom.
Hope that helps.