Skip to content

Instantly share code, notes, and snippets.

@ilguzin
Last active August 29, 2015 14:21
Show Gist options
  • Save ilguzin/ff58a8376228234e1e5b to your computer and use it in GitHub Desktop.
Save ilguzin/ff58a8376228234e1e5b to your computer and use it in GitHub Desktop.
WordPress's workaround for is_ssl() function when proxying from https to http. HTTP_X_FORWARDED_PROTO feature. Stolen from https://wordpress.org/support/topic/request-modify-is_ssl-function-to-check-for-http_x_forwarded_proto
/**
* Determine if SSL is used.
*
* @since 2.6.0
*
* @return bool True if SSL, false if not used.
*/
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;
} elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https' ) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment