Php 注意:未定义索引:中的HTTPS
我有一个问题:如何修复错误注意:未定义的索引:HTTPS中 这是行代码:Php 注意:未定义索引:中的HTTPS,php,Php,我有一个问题:如何修复错误注意:未定义的索引:HTTPS中 这是行代码: public static function getCurrentURL() { $requri = !isset($_SERVER['REQUEST_URI']) ? $_SERVER['PHP_SELF'] : $_SERVER['REQUEST_URI']; $protocol = strtolower($_SERVER["SERVER_PROTOCOL"]); $protocol = sub
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;
如果需要,我在这里发布完整的代码
谢谢。如果禁用HTTPS,则不会定义
$\u服务器['HTTPS']
,从而导致该通知
更改:
($_SERVER['HTTPS']=='on'?'s':'')
致:
这应该适合您:
$protocol = substr($protocol, 0, strpos($protocol, '/')) . (isset($_SERVER['HTTPS']) ? ($_SERVER['HTTPS']=='on'?'s':'' ): '');
您确定协议是HTTPS而不是HTTP吗?因为在这种情况下,没有在服务器上定义索引我更改HTTPS for HTTP,但我得到了这两个错误。下面的答案在这里以表格形式显示:将在编辑方面起作用:您需要学习如何自己修复和调试这些问题。每次收到
未定义索引
通知时都会出现堆栈溢出问题,这是不可持续的。看看isset是如何解决这个问题的,并找出如何应用这些知识。它是固定的,非常感谢。
$protocol = substr($protocol, 0, strpos($protocol, '/')) . (isset($_SERVER['HTTPS']) ? ($_SERVER['HTTPS']=='on'?'s':'' ): '');