Is it possible to conditionally require_once, set global values ​​or set constants?

I have a specific php class that I want to be able to upload identical copies to two different servers. However, depending on the server, the requirements will be located in different places. (constants and global variables are also slightly different) Is it possible to conditionally set require_once, Globals, or constants at the beginning of a file?

+4
source share
2 answers

You can. If this is the way you want to solve the problem, you just need to decide how you are going to determine which server runs this code. You can try using a domain name:

if ($_SERVER['SERVER_NAME'] == 'mydomain1.com') { } else { // default } 
+5
source

Of course:

 <?php if (/* some conditions */) { require_once('some.file.php'); } else { require_once('another.file.php'); } ?> 
+6
source

Source: https://habr.com/ru/post/1307481/


All Articles