DarkxPunk Posted April 24, 2014 Share Posted April 24, 2014 Hi there, I am new to PHP, but have been playing with include for awhile. Today I can't get it to work the normal way I have always worked with it, here is my issue: $contentHome = '../content/public/home.php';switch (true){case $currentSite == "www.domain.tdl" and $currentPage == "home.php":case $currentSite == "domain.tdl" and $currentPage == "home.php":include_once($contentHome);$welcome = $welcome;break; This gives me an error saying the dir does not exist… Now doing a lot of searching I found this solution: define('ROOT', __DIR__.'/');$contentHome = ROOT.'../content/public/home.php';switch (true){case $currentSite == "www.domain.tdl" and $currentPage == "home.php":case $currentSite == "domain.tdl" and $currentPage == "home.php":include_once($contentHome);$welcome = $welcome;break; It works perfect using this code. I understand why, but what I don't understand is why the first example of code does not work!? Thanks for any input. Michael Link to comment Share on other sites More sharing options...
justsomeguy Posted April 24, 2014 Share Posted April 24, 2014 In general both of those should work. Maybe PHP's working directory is set to something else. You can check what the working directory is with this:http://www.php.net/manual/en/function.getcwd.phpYou can also change it:http://www.php.net/manual/en/function.chdir.phpchdir(__DIR__); Link to comment Share on other sites More sharing options...
DarkxPunk Posted April 24, 2014 Author Share Posted April 24, 2014 I checked the the working dir is correct, yet it still does not work the first example. Any other ideas? Link to comment Share on other sites More sharing options...
thescientist Posted April 24, 2014 Share Posted April 24, 2014 why are you using spoiler tags to show code? Link to comment Share on other sites More sharing options...
DarkxPunk Posted April 24, 2014 Author Share Posted April 24, 2014 why are you using spoiler tags to show code? You will notice I am using the proper code tags inside the spoiler tags… Now the reason…well I think it looks cleaner. Just me. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 24, 2014 Share Posted April 24, 2014 The only reason one would work and one would not is if they point to different files. Use realpath to see what the full path is:http://www.php.net/manual/en/function.realpath.phpecho realpath('../content/public/home.php');echo realpath(ROOT.'../content/public/home.php); 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