2016-04-21 27 views
0

我創建一個小網站,我想知道,因爲我對HTTP頭的一些經驗,如果它的安全使用這樣的記錄算法:只在php上重定向非登錄用戶是否安全?

if(! isset($_SESSION["user"]) { 
 

 
header("location : logout.php"); 
 

 
} 
 

 
// and here i start my web page if the conditin above is not satisfied 
 

 
<html> ........

我認爲這不是因爲重定向可以被Web客戶端忽略不是嗎?

+1

只有當您輸出更多隻有授權人員應該看到的內容時,它纔不安全。如果客戶端忽略重定向,並輸出受保護的內容,他們將能夠看到它。 –

回答

1

它甚至更好添加一個「其他」語句只是爲了防止蟲子從曳你: )

if(!isset($_SESSION["user"]) { 

    header("location : logout.php"); 
    exit("you are not authorized!"); 

} else { ?> 
    <html>...</html> 
<?php } ?> 
4

它是「安全的」,當你退出重定向後 - 如果重定向不起作用:

if(! isset($_SESSION["user"]) { 

    header("location : logout.php"); 
    exit("you are not authorized!"); 

} 

// and here i start my web page if the conditin above is not satisfied 

<html> ........