tags:

views:

39

answers:

2

How do i know that this is global or local environment for my php pages

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.

+1  A: 

You could do something like:

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

Then just check whether it is true or false.

Another option is to simply use separate config files, so the config.php on the server is

define("LOCAL_ENV", false);

and the config.php on localhost is

define("LOCAL_ENV", true);
Chacha102
A: 

You can usually find out using

$_SERVER["SERVER_NAME"]

check out phpinfo() and the SERVER section there for a complete list of server side variables, including the current working directory (which is also a pretty good indicator of which server you are working on).

What I like to do is to set up a different config file for each server:

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.

Pekka