Home  >  Article  >  Backend Development  >  代码安全隐患(散分)解决方案

代码安全隐患(散分)解决方案

WBOY
WBOYOriginal
2016-06-13 10:03:161157browse

代码安全隐患(散分)
刚发现自己写的一段验证代码有严重的安全隐患,请大家指教。代码的目的是先通过判断SESSION变量是否注册及其值是否合法,如果验证失败就跳转到登录页面,如果成功才继续往下执行:

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpsession_start ();//$_SESSION['gid'] 是用户登录成功时注册的变量,值1代表管理员组if (!isset($_SESSION['gid']) || ($_SESSION['gid'] != 1)) {  header("location:login.php?".SID);}//do some thing here?>


我以为第一步验证失败后,页面就马上跳转到login.php页了,但实际发现验证没有通过的情况下,也会执行一部分的后续代码(好像没有完整执行),不知道是不是页面跳转需要一定的时间,就在执行跳转这段时间里面又执行了后续的一部分代码?为什么遇到header()函数后不是马上跳转呢?

------解决方案--------------------
session_start(); 
if( 1 != $_SESSION['gid'])) { 
header("location:login.php?".SID); 
exit(); 


//do some thing here 
?> 


自认为良好的风格
------解决方案--------------------

还不懂
慢慢体会
------解决方案--------------------
友情UP
------解决方案--------------------
exit();
------解决方案--------------------
对,要加exit();
------解决方案--------------------
exit()是要加的
LZ真大方,有什么不开心的事要散分哇

------解决方案--------------------
PHP code
<?phpheader ("Location: http://www.example.com/"); /* Redirect browser *//* Make sure that code below does not get executed when we redirect. */exit;?><div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn