The harm of eval function in PHP and the correct disabling method _php tips

Source: Internet
Author: User

The eval function of PHP is not a system component function, so we cannot prohibit it by using disable_functions in php.ini.

But Eval () is very lethal to PHP security, so generally do not use the case in order to prevent similar to the following a word Trojan intrusion, need to prohibit!

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

Eval () Usage Example:

<?php
$string = ' Cup ';
$name = ' coffee ';
$str = ' This $string is fitted with $name .<br> ';
echo $str;
Eval ("$str =" $str ";");
echo $str;
? >

The return value for this example is:

$name is fitted in this $string.
This cup contains coffee.

Or more advanced points are:

<?php
$str = "Hello World";//This is the result of the meta calculation
$code = "Print (' n$strn ');"; /This is stored in the database PHP code
echo ($code);//print the combination of the command, the STR string is replaced to form a complete PHP command, but does not execute
eval ($code);/execute this command
?>

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

This kind of pony smash door situation is need to forbid to drop!
However, many people on the internet say that the use of disable_functions to prohibit the Eval method is wrong!
In fact, eval () cannot be banned by the 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 function;

So how does PHP prohibit eval?

If you want to ban eval, you can use PHP's extended suhosin:
Install Suhosin in php.ini load in suhosin.so, plus suhosin.executor.disable_eval = on can!

To summarize,PHP's eval function is not disabled in PHP, so we only use Plug-ins!

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.