function url(){ if(isset($_SERVER[\'HTTPS\'])){ $protocol = ($_SERVER[\'HTTPS\'] && $_SERVER[\'HTTPS\'] != \"off\") ? \"https\" : \"http\"; }
Use SERVER_NAME.
SERVER_NAME
echo $_SERVER['SERVER_NAME']; //Outputs www.example.com