2016-03-01 51 views
0

我正在爲DJ(真的)做一個DJ面板。有時技術人員希望更新網站,因此需要有一個「維護腳本」來禁用整個網站。如果用戶是管理員禁用維護,如果用戶是正常的啓用維護

// The website is connected to DB and session is running 

// if maintenance is enabled, throw the maintenance page in there and exit everything else 
if($maintenance) {include("inc/maintenance.php");exit();} 

// fetch the db info for the maintenance script 
$statussen1 = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM status3 WHERE naam='onderhoud'"); 
$statussen = mysqli_fetch_array($statussen1); 

// check if 'maintenance' row in the DB is set to AAN (means ON in Dutch) 
if(htmlentities($statussen['status']) == 'AAN') { 

// if maintenance is AAN, check if the user is an staff member 
if(htmlentities($gegevens['rang']) == '1' // owner 
OR htmlentities($gegevens['rang']) == '2' // head dj 
OR htmlentities($gegevens['rang']) == '3' // assistant head dj 
OR htmlentities($gegevens['rang']) == '4' // pilot dj 
OR htmlentities($gegevens['rang']) == '5' // test dj 
OR htmlentities($gegevens['rang']) == '6' // something else, not sure what 6 is called :P 
OR htmlentities($gegevens['nieuwsreporter']) == '1' 
OR htmlentities($gegevens['moderator']) == '1') { 
    // disable the maintenance script if staff 
    $maintenance = false; 
} else { 
    // or if the user is no staff, enable the maintenance script 
    $maintenance = true; 
} 
} 

我想我已經做得很好,試圖在腳本中解釋它是什麼,所以你會明白它更好一點。但是,當DB中的維護設置爲AAN時,該腳本給了我一個空白頁面。

我已經檢查了100次腳本,但找不到與問題相關的任何內容。是啊,我已經設置錯誤報告給E_ALL,只給了我這個錯誤:7

Notice: Undefined variable: maintenance in xxx on line 7

線是

if($maintenance) {include("inc/maintenance.php");exit();} 

但是,這不應該是導致空白頁的實際問題。我一定在某個地方做錯了事。請幫助我。

+0

它看起來像你使用$維護之前,你正在設置它。 –

+0

@ Cayde6嘿Cayde,我編輯了我的代碼,但沒有成功。 – Carl

+0

你能否爲我們確定第7行?據我所知,第7行有一條評論,並且PHP將不得不超出fubar才能發生。謝謝。 – MonkeyZeus

回答

0

你的7號線更改爲

if(isset($maintenance)) {include("inc/maintenance.php");exit();} 

,所以它看起來像這樣,然後編輯您的代碼的其餘部分:

// The website is connected to DB and session is running 


// you can't use maintenance up here, php knows nothing about this variable. 
// it needs to be set before you can use it 

// fetch the db info for the maintenance script 
$statussen1 = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM status3 WHERE naam='onderhoud'"); 
$statussen = mysqli_fetch_array($statussen1); 

// check if 'maintenance' row in the DB is set to AAN (means ON in Dutch) 
if(htmlentities($statussen['status']) == 'AAN') { 

    // if maintenance is AAN, check if the user is an staff member 
    if(htmlentities($gegevens['rang']) == '1' // owner 
    OR htmlentities($gegevens['rang']) == '2' // head dj 
    OR htmlentities($gegevens['rang']) == '3' // assistant head dj 
    OR htmlentities($gegevens['rang']) == '4' // pilot dj 
    OR htmlentities($gegevens['rang']) == '5' // test dj 
    OR htmlentities($gegevens['rang']) == '6' // something else, not sure what 6 is called :P 
    OR htmlentities($gegevens['nieuwsreporter']) == '1' 
    OR htmlentities($gegevens['moderator']) == '1') { 
     // disable the maintenance script if staff 
     $maintenance = false; 
    } else { 
     // or if the user is no staff, enable the maintenance script 
     $maintenance = true; 
     // if maintenance is enabled, throw the maintenance page in there and exit everything else 
     include("inc/maintenance.php");exit(); 
    } 
} 
+0

謝謝,我解決了這個問題。我認爲這是我的代碼更大的問題。再次感謝。 – Carl

0

它的設置前,你檢查的$maintenance值。把它往下移過else

// fetch the db info for the maintenance script 
$statussen1 = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM status3 WHERE naam='onderhoud'"); 
$statussen = mysqli_fetch_array($statussen1); 

// check if 'maintenance' row in the DB is set to AAN (means ON in Dutch) 
if(htmlentities($statussen['status']) == 'AAN') { 

    // if maintenance is AAN, check if the user is an staff member 
    if(htmlentities($gegevens['rang']) == '1' // owner 
    OR htmlentities($gegevens['rang']) == '2' // head dj 
    OR htmlentities($gegevens['rang']) == '3' // assistant head dj 
    OR htmlentities($gegevens['rang']) == '4' // pilot dj 
    OR htmlentities($gegevens['rang']) == '5' // test dj 
    OR htmlentities($gegevens['rang']) == '6' // something else, not sure what 6 is called :P 
    OR htmlentities($gegevens['nieuwsreporter']) == '1' 
    OR htmlentities($gegevens['moderator']) == '1') { 
     // disable the maintenance script if staff 
     $maintenance = false; 
    } else { 
     // or if the user is no staff, enable the maintenance script 
     $maintenance = true; 
    } 
    // if maintenance is enabled, throw the maintenance page in there and exit everything else 
    if($maintenance) { 
     include("inc/maintenance.php"); 
     exit(); 
    } 
} 
+0

感謝您的意見,我解決了這個問題。我有一個公平的比賽,並將bmcculley標記爲接受的答案,他比你快40秒。我很抱歉,但我希望你過得愉快! – Carl