PHP determine if using SSL HTTPS or HTTP
To determine if SSL is used, the is_ssl()
function will return True
if the page is using SSL (HTTPS or on Port 443), False if not
used.
// From wordpress/wp-includes/load.php
// Previously wordpress/wp-includes/functions.php
function is_ssl() {
if ( isset( $_SERVER['HTTPS'] ) ) {
if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) {
return true;
}
if ( '1' == $_SERVER['HTTPS'] ) {
return true;
}
} elseif ( isset($_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
return true;
}
return false;
}
4 comments
thanks for posting this, it helped me big time today
Link to original source file
http://core.svn.wordpress.org/trunk/wp-includes/functions.php
wtf it should be if ( $_SERVER['HTTPS'] = '1' etc..
var you are checking = the value you want to check it against
Link to latest https://github.com/WordPress/WordPress/blob/HEAD/wp-includes/load.php
Leave a Reply