phpDevNeeded Posted April 27, 2022 Share Posted April 27, 2022 Hi there, Due to how our web servers are set up, my include file path has to be different on the live server vs the dev server. On live, it is: <?php include('/blah/blah/blah/my_file.php'); ?> On dev, it is: <?php include('/blah/my_file.php'); ?> Is it possible to set up a conditional include in PHP? i.e. On dev display one path, but on live display another path for the same file? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/314732-conditional-includes-in-php/ Share on other sites More sharing options...
kicken Posted April 27, 2022 Share Posted April 27, 2022 Yes, you can use variables in your path, so you could define a separate prefix for each environment. However, usually it's easier to use the built in __DIR__ constant and build a path that's relative to the current file. For example: include(__DIR__.'/my_file.php'); Quote Link to comment https://forums.phpfreaks.com/topic/314732-conditional-includes-in-php/#findComment-1595739 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.