Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/314732-conditional-includes-in-php/
Share on other sites

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');

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.