Skip to content

Instantly share code, notes, and snippets.

@trey
Created February 15, 2012 23:28
Show Gist options
  • Save trey/1840023 to your computer and use it in GitHub Desktop.
Save trey/1840023 to your computer and use it in GitHub Desktop.
Host name switching in PHP
<?php
switch($_SERVER['HTTP_HOST'])
{
case 'something.dev':
case 'something-else.dev':
// Development settings
break;
case 'something.com':
// Staging settings
break;
default:
// Production settings
}
?>
@akuzemchak
Copy link

the switch statement would work as well.

switch($_SERVER['HTTP_HOST'])
{
    case 'something.dev':
    case 'something-else.dev':
        // Development settings
    break;

    case 'something.com':
        // Staging settings
    break;

    default:
        // Production settings
}

@trey
Copy link
Author

trey commented Feb 16, 2012

@akuzemchak, nice. That is a lot cleaner. That little snippet is pretty old, but I think the reason I wrote it that way was so that I could have a list of different development servers. Or maybe because I just didn't thinking of actually using a case statement. :)

@akuzemchak
Copy link

In all fairness, it wasn't until maybe 6 months ago that I realized you could have multiple cases per block, and without that ability, it would be pointless :)

@trey
Copy link
Author

trey commented Feb 16, 2012

Oh, snap! I didn't even realize you were doing that. That is much cooler. 👍

@trey
Copy link
Author

trey commented Feb 16, 2012

@akuzemchak I updated my snippet to your code. :) Thanks.

@akuzemchak
Copy link

Yay! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment