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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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