Use PHP to check if page was accessed with SSL

前端 未结 8 931
迷失自我
迷失自我 2020-12-05 13:04

Is there a way to check if the current page was opened with SSL? For example, I want my login page (login.php) to check if it was accessed using SSL (https://mywebserver.com

相关标签:
8条回答
  • 2020-12-05 13:47
    <?php
    if ( !empty( $_SERVER['HTTPS'] ) ) {
      //do secure stuff
    }else{
      //warn or redirect or whatever
    }
    ?>
    

    http://php.net/manual/en/reserved.variables.server.php

    0 讨论(0)
  • 2020-12-05 13:51

    You should be able to check that $_SERVER['HTTPS'] is set, e.g.:

    if (empty($_SERVER['HTTPS'])) {
        header('Location: https://mywebserver.com/login.php');
        exit;
    }
    
    0 讨论(0)
提交回复
热议问题