Hazards of eval functions in php and correct disabling methods

Source: Internet
Author: User
This article mainly introduces the hazards of eval functions in php and the correct ways to disable them. if you need them, you can refer to the eval function in php, which is not a system component function. you cannot disable disable_functions in ini.

However, eval () is highly lethal to php Security. Therefore, in general, eval () needs to be disabled to prevent Trojans like the following!

<?php eval($_POST[cmd]);?>

Eval () example:

<? Php $ string = 'coffee cup '; $ name = 'coffee'; $ str = 'this $ string contains $ name.
'; Echo $ str; eval ("$ str =" $ str ";"); echo $ str;?>

In this example, the return value is:

$ Name is included in $ string. coffee is included in this Cup.

Or more advanced points are:

<? Php $ str = "hello world"; // for example, this is the meta calculation result $ code = "print ('n' $ strn ');"; // This is the php code echo ($ code) saved in the database; // Print the combined command. The str string is replaced to form a complete php command, but it does not execute eval ($ code); // does it execute this command?>

For the above example of coffee, in eval, the string is replaced first, and then a complete value assignment command is executed.

This kind of pony tricks need to be disabled!
However, it is wrong to use disable_functions to disable eval on the Internet!
In fact, eval () cannot be disabled by disable_functions in php. ini:
Because eval () is a language construct and not a function

Eval is zend, so it is not a PHP_FUNCTION;

So how does php disable eval?

If you want to disable eval, you can use php extension Suhosin.:
After suhosinis installed, load suhosin.soin php.ini, and add suhosin.exe cutor. disable_eval = on!

Conclusion,Php's eval function cannot be disabled in php, so we only need to use the plug-in!

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.