Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - If domain

I have the following piece of coding on a multi-domain 1 template setup:

<?php  $host = parse_url($domain, PHP_URL_HOST);
if($host == 'www.justdoors.co') {
echo "action goes here";
} ?>

For some reason it's not carrying out the action when I'm on the www.justdoors.co domain, what am I missing?

like image 286
Vince P Avatar asked Jun 29 '11 14:06

Vince P


3 Answers

Use $_SERVER['SERVER_NAME'] or $_SERVER['HTTP_HOST'] variable

 $host = $_SERVER['HTTP_HOST']; 
 if($host == "www.justdoors.co" or $host == "justdoors.co") {
     //do anything you want to do 
 }
like image 193
genesis Avatar answered Oct 04 '22 21:10

genesis


I have used this successfully on my server before.

<?php if ( $_SERVER['SERVER_NAME'] == 'www.domain.com' ) { echo ''; } ?>
like image 42
Frank Martin Avatar answered Oct 04 '22 21:10

Frank Martin


I have tried this and it's working perfectly ..

<?php
function conn()
{
    $ora_con=0;
    //development connection building
    if ( $_SERVER['SERVER_NAME'] == 'xyz.com' ) 
    {$username='scott';
     $password = 'tiger';
     $ora_conn_string = 'conn_name:port_no/db_name';
     //echo "<br>development connection building";
      $ora_con = oci_connect($username,$password,$ora_conn_string);
     //echo '<br>dev connection build<br>';
    }
    //Production connection building
    elseif ( $_SERVER['SERVER_NAME'] == 'abc.net' ) 
        {$username='prod_scott';
         $password = 'prod_tiger';
         $ora_conn_string = 'conn_name:port_no/db_name';
         //echo "<br>Production connection building";
         $ora_con = oci_connect($username,$password,$ora_conn_string);
         //echo '<br>Prod connection build<br>';
        }

    return $ora_con;
}
?>
like image 37
jatingoel1349 Avatar answered Oct 04 '22 23:10

jatingoel1349