2016-04-21 61 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> ........