2014-11-24 79 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':''): '');