我有一个问题:如何修复错误注意:未定义的索引:HTTPS in。
这是行代码:
public static function getCurrentURL() {
$requri = !isset($_SERVER['REQUEST_URI']) ? $_SERVER['PHP_SELF'] : $_SERVER['REQUEST_URI'];
$protocol = strtolower($_SERVER["SERVER_PROTOCOL"]);
$protocol = substr($protocol, 0, strpos($protocol, '/')) . ($_SERVER['HTTPS']=='on'?'s':'');
$port = $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT'];
return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $requri;
}
有错误的行:
$protocol = substr($protocol, 0, strpos($protocol, '/')) . ($_SERVER['HTTPS']=='on'?'s':'');
我收到此错误提示:未定义索引:第30行中的UID:
$_UID = $_COOKIE['UID'] ? $_COOKIE['UID'] : 0;
并且此错误注意:未定义的变量:第27行中的G_UID:
if ($G_UID && $G_URL && $G_ADT) {
$surl = SITE_LOCATION;
$db = System::getDB();
$user = $G_UID;
如果需要,我在这里完成代码。
谢谢。
答案 0 :(得分:3)
如果HTTPS已关闭,则不会定义$_SERVER['HTTPS']
,从而导致该通知。
变化:
($_SERVER['HTTPS']=='on'?'s':'')
为:
(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on'?'s':'')
答案 1 :(得分:0)
这应该适合你:
$protocol = substr($protocol, 0, strpos($protocol, '/')) . (isset($_SERVER['HTTPS']) ? ($_SERVER['HTTPS']=='on'?'s':'' ): '');