如何解决这个“;未定义索引“;if语句


How to fix this "undefined index" if statement

我的代码低于

$base = if((!empty(($_SERVER['HTTPS']  ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/'));

我正在检查$_SERVER['HTTPS']是否为空,但我收到了以下通知:

注意:未定义的索引:第24行上D:''examplep''htdocs''flowershop ''flowers.php中的HTTPS

以下代码应该可以工作。如果您注意到,在PHP简写中,您没有包含if单词。

<?php
   $base = (isset($_SERVER['HTTPS']) ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].'/';
?>

我不会依赖$_SERVER['HTTP_HOST'],因为客户端可以修改它,并且可能会导致一些巨大的问题。