Jump to content

include with root link?


eiranix

Recommended Posts

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

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 by niche
Link to comment
Share on other sites

You would've found it unless you turned off error reporting which isn't a good idea.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...