2015-04-03 33 views
0

我正在使用留言簿與分頁。 因此,在url中是這樣的:http://example.com/guestbook/guestbook.php?page=6 當在還不存在的url中輸入一個頁面(例如page = 9999) 他給了我回聲:「成爲第一個寫在留言簿中的人」 How我可以把所有那些不存在的頁面放到404上嗎?如何在頁面不存在時爲留言簿添加404

if (mysqli_num_rows($results) != 0) { // if DB is not empty 

// display records 
while ($row = mysqli_fetch_array($results)) 
{ ?> 
    <div class="wrapper"> 

     <div class="velden"> <!-- for styling echos; CSS --> 
      <div class="header"> 
       <div class="naam"><?php echo htmlspecialchars($row['name'], ENT_QUOTES, UTF-8, true); ?></div> <!-- echo naam--> 
       <div class="email"><?php echo htmlspecialchars($row['email'], ENT_QUOTES, UTF-8, true); ?></div> <!-- echo email--> 
       <div class="tijd"><?php echo $row['datetime']; ?></div> <!-- echo datum en tijd--> 

      </div> 

      <div class="bericht"><?php echo htmlspecialchars($row['message'], ENT_QUOTES, UTF-8, true); ?></div> <!-- echo bericht--> 

     </div> <!-- end velden --> 

<?php } ?> 


     <?php echo pagination($statement,$per_page,$page,$url='?'); ?> 
    </div> 


<?php } else { // DB is emtpy 
echo "Be the first to write in the Guestbook"; 
} 
+1

你是說要返回頭404? – 2015-04-03 18:49:28

+0

是的,這是真的;在這種情況下返回一個404頭,而不是回聲 – 2015-04-03 19:01:43

回答

1

像這樣的東西可能會有所幫助:

else { // DB is emtpy 
    if (isset($_GET['page']]) { 
     echo 'Page 404'; 
    } else { 
     echo "Be the first to write in the Guestbook"; 
    } 
} 

這個擴展,雖然不是很漂亮,我會說。你可以在你發佈的部分之前使用你的代碼(在你解析數據的地方進行mysql查詢)來獲得相同的結果,並得到更清晰的代碼。

2

在其他

header('HTTP 1.1 404 Not Found'); 
相關問題