开发者

How can I use local and remote settings in the same PHP file?

开发者 https://www.devze.com 2023-02-04 00:16 出处:网络
My basic thoughts would be to do something like: $isLocal = // test here if ($isLocal) { // local settings here

My basic thoughts would be to do something like:

$isLocal = // test here

if ($isLocal) {
// local settings here
}
else {
// remote settings here
}

I've tried $_SERVER['HTTP_HOST'] but when I debug in Netbeans, H开发者_运维技巧TTP_HOST does not appear as a parameter. Basically I'm looking for a robust test for $isLocal


You should probably keep distinct configuration files for each server and exclude them from your revision control system...

require_once '/config.local.php';

This has the advantage of scaling out to as many development servers as you want, while keeping the live configuration independent and private.


try

 $_SERVER['SERVER_NAME'];

local address will be different from real


Can you pass a string via the $_GET variable? If you were to add ?local=true to your URLs and then test for this then this would be one way of accomplishing this quite easily. Just remember to disable when it goes live.

0

精彩评论

暂无评论...
验证码 换一张
取 消