yerel ve küresel sunucuyu nasıl ayırt

2 Cevap php

Nasıl bu benim php sayfaları için genel veya yerel ortam olduğunu biliyor musunuz

means i m using Google map Key there is two different key one for local server and another for that domain where it has to be shown, so how do i write the code for both keys together and page automaticaaly detect that which key have to be use

these things i also want to apply for config files i want that when site is on the web server , config files take username and password of that server otherwise take local user and password.

2 Cevap

Gibi bir şey yapabilirsiniz:

if($_SERVER['HTTP_HOST'] == "localhost")
{
    define("LOCAL_ENV", true);
}
else
{
    define("LOCAL_ENV", false);
}

Sonra sadece doğru veya yanlış olup olmadığını kontrol edin.

Başka bir seçenek sadece ayrı yapılandırma dosyaları kullanmak için, bu nedenle sunucu üzerinde config.php olduğunu

define("LOCAL_ENV", false);

ve localhost config.php olduğunu

define("LOCAL_ENV", true);

Genellikle kullanarak öğrenebilirsiniz

$_SERVER["SERVER_NAME"]

phpinfo() ve (aynı zamanda üzerinde çalışmakta olduğunuz sunucu oldukça iyi bir gösterge olduğu) geçerli çalışma dizini dahil sunucu tarafı değişkenler, tam listesi için orada SERVER bölümüne göz atın.

Ne yapmak istiyorum, her sunucu için farklı bir yapılandırma dosyası kurmak için:

setup.localhost.php
setup.example.com.php

That way, I don't have to switch anything. You should just turn that off for production use, as $_SERVER["SERVER_NAME"] could probably be faked under some virtual host settings.