eiranix Posted October 5, 2014 Share Posted October 5, 2014 I want to include a file on all the pages of my site, but some of those pages are in subfolders. I would like to get around putting ../ on some pages and not others so I used an if statement: <?php if (file_exists('menu.php')) { include 'menu.php'; } else { include '../menu.php'; }; ?> So my question is, is this the best way to do it? Any danger that this won't work? I have tried using $_SERVER['SITE_HTMLROOT'] without success, Link to comment Share on other sites More sharing options...
niche Posted October 5, 2014 Share Posted October 5, 2014 (edited) Whatever make the most sense to you. Test it and maintain the file structure and all will be well. EDIT: You don't need that last semi colon. Edited October 5, 2014 by niche Link to comment Share on other sites More sharing options...
eiranix Posted October 5, 2014 Author Share Posted October 5, 2014 Great thanks. I'm new to php so I like to check things sometimes! Link to comment Share on other sites More sharing options...
niche Posted October 6, 2014 Share Posted October 6, 2014 You would've found it unless you turned off error reporting which isn't a good idea. Link to comment Share on other sites More sharing options...
eiranix Posted October 10, 2014 Author Share Posted October 10, 2014 (edited) Edit: somehow posted on the wrong thread... Edited October 10, 2014 by eiranix Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now