Code security hazards (scattered points) solution-php Tutorial

Source: Internet
Author: User
Code security hazards (scattered points) I just found that a piece of verification code I wrote has serious security risks. please advise. The purpose of the code is to first determine whether the SESSION variable is registered and whether its value is valid. if the verification fails, it will jump to the logon page. if the verification succeeds, it will continue to execute: PHPcode & lt ;? Phpsession_start (); $ _ SESSION [gid] is a variable registered when the user logs on successfully. value 1 indicates the administrator group if (! Iss code security hazards (discrete)
I just found that a piece of verification code I wrote has serious security risks. please advise. The purpose of the code is to first determine whether the SESSION variable is registered and whether its value is valid. if the verification fails, the code jumps to the logon page. if the verification succeeds, the code continues to run:

PHP code
  
  


I thought the page will jump to login immediately after the first verification fails. the php page is displayed, but if the verification fails, some subsequent code will be executed (it seems that the code is not fully executed). I don't know if it takes some time to jump to the page, during the execution jump period, some subsequent code is executed? Why didn't I jump to the header () function immediately?

------ Solution --------------------
Session_start ();
If (1! = $ _ SESSION ['gid']) {
Header ("location: login. php? ". SID );
Exit ();
}

// Do some thing here
?>


Self-considered good style
------ Solution --------------------

Not understand
Experience
------ Solution --------------------
Friendship UP
------ Solution --------------------
Exit ();
------ Solution --------------------
Yes, add exit ();
------ Solution --------------------
Exit () is to be added
LZ is really generous. What are you unhappy about?

------ Solution --------------------
PHP code
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.