Undefined index error using $_SERVER['HTTPS']

前端 未结 2 1180
挽巷
挽巷 2020-12-10 02:53

Debug is throwing...

Notice: Undefined index: HTTPS in C:\\xampplite\\htdocs\\testsite\\wp-content\\themes\\mytheme\\header.php on line 4

相关标签:
2条回答
  • 2020-12-10 03:01

    Some servers simply don't set $_SERVER['HTTPS'] if the request is non-secure. Some others may set it to 'off'. You'll have to check it like this:

    if ( isset( $_SERVER["HTTPS"] ) && strtolower( $_SERVER["HTTPS"] ) == "on" ) {
        $pageURL .= "s";
    }
    
    0 讨论(0)
  • 2020-12-10 03:02

    Notice: Undefined index: HTTPS says that HTTPS is not a key within the $_SERVER array. It doesn't exist, so you can't compare it with "on".

    isset() checks whether a variable is "set" or even available for reference in this case. This would be the best choice in your case.

    0 讨论(0)
提交回复
热议问题