vampke Posted February 27, 2013 Share Posted February 27, 2013 Hi peepz, I am writing a script that seems to be doing what I mean it to except for one thing. I have a file in a subdirectory (uri/includes) which I include in my php files of the parent directory (uri): include 'firstfile.inc.php'; The firstfile.inc.php file includes another file in the same includes directory. include 'secondfile.inc.php'; On my local windows machine this works fine. On my linux webserver not so much: in stead of including the file in 'uri/includes/secondfile.inc.php' it tries to include 'uri/secondfile.inc.php' Could anyone be so kind to explain why this is happening (a server setting I need to be looking at?) and how to overrun this setting in the code? I am on a shared hosting account with no access to php.ini. Cheers. v. Quote Link to comment https://forums.phpfreaks.com/topic/275026-includes-not-working-consistently-on-different-servers/ Share on other sites More sharing options...
requinix Posted February 27, 2013 Share Posted February 27, 2013 Anecdotally, the rules for finding pathless files with include() has varied over time and PHP versions: sometimes it might search the directory of the parent file, sometimes it only looks at the working directory. The best thing to do is be very explicit with your filenames by using absolute paths. For something relative to the directory of the parent file you can include __DIR__ . '/firstfile.inc.php'; // PHP 5.3+ include dirname(__FILE__) . '/firstfile.inc.php'; and for something relative to the root of your website, include $_SERVER['DOCUMENT_ROOT'] . '/includes/firstfile.inc.php'; Quote Link to comment https://forums.phpfreaks.com/topic/275026-includes-not-working-consistently-on-different-servers/#findComment-1415449 Share on other sites More sharing options...
vampke Posted February 28, 2013 Author Share Posted February 28, 2013 thanks for your reply requinix. I was not aware of this. It seems like very poor consistency in php... I already came up with a solution similar to yours, however I was looking for a reason for the incongruity. Very surprised to find it out. Quote Link to comment https://forums.phpfreaks.com/topic/275026-includes-not-working-consistently-on-different-servers/#findComment-1415573 Share on other sites More sharing options...
requinix Posted February 28, 2013 Share Posted February 28, 2013 It's an evolving language. It's not like you can expect HTML 5 to behave the same way as HTML 3, right? Quote Link to comment https://forums.phpfreaks.com/topic/275026-includes-not-working-consistently-on-different-servers/#findComment-1415645 Share on other sites More sharing options...
Christian F. Posted March 1, 2013 Share Posted March 1, 2013 This also depends upon the host's configuration, mind you. Most hosts I've seen, however, will at least allow for the include to be relative to the main file. The same with most PHP versions I've encountered, at least the last few (7+) years. Quote Link to comment https://forums.phpfreaks.com/topic/275026-includes-not-working-consistently-on-different-servers/#findComment-1415795 Share on other sites More sharing options...
vampke Posted March 1, 2013 Author Share Posted March 1, 2013 @requinix: I understand the language evolves, but there really is no logical explanation to changing these kind of things is there? @christian: which setting would i need to be looking at? Quote Link to comment https://forums.phpfreaks.com/topic/275026-includes-not-working-consistently-on-different-servers/#findComment-1415828 Share on other sites More sharing options...
Christian F. Posted March 1, 2013 Share Posted March 1, 2013 The include path directive. Quote Link to comment https://forums.phpfreaks.com/topic/275026-includes-not-working-consistently-on-different-servers/#findComment-1415839 Share on other sites More sharing options...
requinix Posted March 1, 2013 Share Posted March 1, 2013 Also the documentation for include() explains the logic used. I understand the language evolves, but there really is no logical explanation to changing these kind of things is there?Unless the change was for the better. Quote Link to comment https://forums.phpfreaks.com/topic/275026-includes-not-working-consistently-on-different-servers/#findComment-1415872 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.