Empty ($_server[' Http_via ')) or exit (' Access Denied '); What's the role of PHP in this line?

Source: Internet
Author: User
Look at someone else's anti-attack code that has this line:

empty($_SERVER['HTTP_VIA']) or exit('Access Denied');

What's the effect?

Reply content:

Look at someone else's anti-attack code that has this line:

empty($_SERVER['HTTP_VIA']) or exit('Access Denied');

What's the effect?

The landlord may be puzzled by the problem of or
This kind of writing is a commonly used procedural technique of PHP.
A or B, as long as AB has one satisfying true, it executes the following statement immediately.
When a is not true, or is not immediately determined, it also needs to go down to the second condition B, and the result B will exit directly, so it looks a little more concise than the IF statement. In other words, if a is true, then access denied will not be executed.

In fact, the main use of the following points:

    1. Or with left-to-right binding

    2. In the or condition, only one condition is true, then the remaining condition is not judged, and the code snippet in the braces is executed directly.

    3. This is more beautiful than if (empty (XXX)) {xxxx}

If there is any mistake, please correct me.

Prevent users from running to this program in the right way.

$_SERVER['HTTP_VIA']Is the proxy server address, that is, if the user is accessed through a proxy, it will exit directly and will not continue to execute. This is a measure to ensure security.

The proxy server IP is not empty when exiting the current program and outputting Access Denied to prevent external attacks.

  • 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.