2014-11-24 54 views
-2

我有一个问题:如何固定的错误注意:未定义指数:HTTPS在注意:未定义指数:HTTPS在

这行代码:

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; 
} 

与错误行:

在第30行UID:
$protocol = substr($protocol, 0, strpos($protocol, '/')) . ($_SERVER['HTTPS']=='on'?'s':''); 

我得到这个错误的通知:未定义指数

$_UID = $_COOKIE['UID'] ? $_COOKIE['UID'] : 0; 

而这个错误注意:未定义的变量:G_UID在第27行:

if ($G_UID && $G_URL && $G_ADT) { 
    $surl = SITE_LOCATION; 
    $db = System::getDB(); 
    $user = $G_UID; 

如果需要,我在这里发布的代码完成。

谢谢。

+0

你确定,该协议是HTTPS,而不是HTTP?原因在这种情况下索引未在服务器上定义 – 2014-11-24 13:46:39

+0

我更改HTTP的HTTPS,但我得到两个错误。 – 2014-11-24 13:48:50

+0

下面的答案这是从这里形式:http://stackoverflow.com/questions/4911532/undefined-index-error-using-serverhttps将工作 – 2014-11-24 13:49:30

回答

3

如果HTTPS关闭,$_SERVER['HTTPS']将不会被定义,导致该通知。

变化:

($_SERVER['HTTPS']=='on'?'s':'') 

到:

(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on'?'s':'') 
+0

它是固定的,非常感谢。 – 2014-11-24 13:54:45

0

这应该为你工作:

$protocol = substr($protocol, 0, strpos($protocol, '/')) . (isset($_SERVER['HTTPS']) ? ($_SERVER['HTTPS']=='on'?'s':''): '');