is_ssl()检查ssl是否可用

目录

描述

Checks if SSL is being used.

is_ssl() 描述

用法

<?php is_ssl() ?>

is_ssl() 用法

参数

This tag has no parameters.

is_ssl() 参数

返回值

(bool) 

Returns true or false

is_ssl() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<?php 
  if (is_ssl()) {
    //action to take for page using SSL
  }
?>

is_ssl() 示例

注意

Returns true if the page is using SSL (checks if HTTPS or on Port 443).

NB: this won't work for websites behind some load balancers, especially Network Solutions hosted websites. To bodgy up a fix, save this gist into the plugins folder and enable it. For details, read WordPress is_ssl() doesn’t work behind some load balancers.

Websites behind load balancers or reverse proxies that support HTTP_X_FORWARDED_PROTO can be fixed by adding the following code to the wp-config.php file, above the require_once call:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
    $_SERVER['HTTPS'] = 'on';

is_ssl() 注意

历史

添加于 版本: 2.6.0

is_ssl() 历史

源文件

is_ssl() 函数的代码位于 wp-includes/functions.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * 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;
	}
	return false;
}

is_ssl() 源文件

相关