显示 PHP 错误通知


PHP Error Notice Show

<?php
if ($_SERVER['HTTPS']) {
    $base_url='https://' . $_SERVER['SERVER_NAME'];
} else {
    $base_url= 'http://' . $_SERVER['SERVER_NAME'];
}
?>

我在我的索引页中编写此代码。 以及我使用的所有其他页面

<?php print''.$base_url.''; ?>/Views/Patient/patientList.php

但是当我运行我的网站时,显示一个通知

注意:未定义的索引:C:''xampp''htdocs''dopatient''index.php 第 6 行中的 HTTPS

用于正确检查索引是否存在:

$base_url = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://' ) . $_SERVER['SERVER_NAME'];

(或者:

$base_url = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://' );
$base_url .= $_SERVER['SERVER_NAME'];

您需要检查"on"值,因为_SERVER['HTTPS']也可以"关闭"。请参阅HTTPS位:http://php.net/manual/en/reserved.variables.server.php