Jump to content

Localhost Conditional Statement


alingham

Recommended Posts

Hi there...

 

I am wanting to have an easy conditional statement that will allow scripts to perform slightly differently if its on a localhost testing server?

Currently, the online server I have won't allow me to connect to the MySQL database using 'localhost' as the host. Instead it has to be hard wired in with their server name.

This causes problems on the localhost server in not being able to connect to that server from outside.

 

So I need a conditional statement that will recognise when its on localhost and when its not, so that the MySQL host can change appropriately without me having to re-type it out when I upload the files.

 

Cheers in advance,

Link to comment
https://forums.phpfreaks.com/topic/121498-localhost-conditional-statement/
Share on other sites

another alternative is to just set a series of constants that define paths, server variables and whatnot, which assign differently depending on another defined constant - then just use that as your basis of switching:

 

define('THIS_ENVIRONMENT', 0);

if (THIS_ENVIRONMENT === 0)
{
  // define local settings
}
else
{
  // define server settings
}

 

it ain't pretty, but the reality is, any other contingency coding would be doing the exact same thing.  it's also a good reason to have a collected settings file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.