26
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

is_ssl() : HTTPSプロトコルかどうかを返す

Posted at

なんか大掛かりになったけど、こんなんでいいんじゃないかな…?
ツッコミほしい…。

<?php
/**
 * Determine if the protocol is HTTPS.
 * @return bool
 */
public function is_ssl()
{
	if ( isset($_SERVER['HTTPS']) === true ) // Apache
	{
		return ( $_SERVER['HTTPS'] === 'on' or $_SERVER['HTTPS'] === '1' );
	}
	elseif ( isset($_SERVER['SSL']) === true ) // IIS
	{
		return ( $_SERVER['SSL'] === 'on' );
	}
	elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) === true ) // Reverse proxy
	{
		return ( strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https' );
	}
	elseif ( isset($_SERVER['HTTP_X_FORWARDED_PORT']) === true ) // Reverse proxy
	{
		return ( $_SERVER['HTTP_X_FORWARDED_PORT'] === '443' );
	}
	elseif ( isset($_SERVER['SERVER_PORT']) === true )
	{
		return ( $_SERVER['SERVER_PORT'] === '443' );
	}

	return false;
}
26
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?