LoginSignup
7
4

More than 5 years have passed since last update.

【超小ネタ】IISを考慮した $_SERVER['HTTPS'] のチェック

Posted at

$_SERVER['HTTPS'] に関して.

スクリーンショット 2016-06-02 19.27.18.png

ということなので…

if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
    /* HTTPS */   
} else {
    /* HTTP */   
}

普通はこう書きますが

スクリーンショット 2016-06-02 19.31.21.png

こんなフィルタがあるので以下のようにも書けます

if (filter_input(INPUT_SERVER, 'HTTPS', FILTER_VALIDATE_BOOLEAN)) {
    /* HTTPS */   
} else {
    /* HTTP */   
}

微妙に長くなった気がするけどこっちのほうが分かりやすい(気がしなくもない)

7
4
1

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
7
4