wpXtreme / wpdk

WordPress Development Kit
http://wpxtreme.github.io/wpdk/
Other
78 stars 19 forks source link

Current URL #1

Closed gfazioli closed 11 years ago

gfazioli commented 11 years ago

In some server configurations (like linux with Cpanel and nginx) the method currentURL prepend the www. Use:

function get_host() {                                                                     
    if ($host = $_SERVER['HTTP_X_FORWARDED_HOST'])                                        
    {                                                                                     
        $elements = explode(',', $host);                                                  

        $host = trim(end($elements));                                                     
    }                                                                                     
    else                                                                                  
    {                                                                                     
        if (!$host = $_SERVER['HTTP_HOST'])                                               
        {                                                                                 
            if (!$host = $_SERVER['SERVER_NAME'])                                         
            {                                                                             
                $host = !empty($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '';   
            }                                                                             
        }                                                                                 
    }                                                                                     

    // Remove port number from host                                                       
    $host = preg_replace('/:\d+$/', '', $host);                                           

    return trim($host);                                                                   
}                                                                                         
gfazioli commented 11 years ago

Closed!!