Determine whether https
/** * Determine whether https * @Return bool return true https; otherwise false */ function is_https() { if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { return true; } elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) { return true; } elseif ( !empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { return true; }else{ return false; } }
// Get the domain name or host address echo $_SERVER['HTTP_HOST']."<br>"; #localhost // Get the web address echo $_SERVER['PHP_SELF']."<br>"; #/blog/testurl.php // Get URL parameters echo $_SERVER["QUERY_STRING"]."<br>"; #id=5 // Get the user agent echo $_SERVER['HTTP_REFERER']."<br>"; // get the full url echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']; #http://localhost/blog/testurl.php?id=5 // contains the full url port numbers echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; #http://localhost:80/blog/testurl.php?id=5 // just take the path $url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]; echo dirname($url); #http://localhost/blog