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

Source: Internet
Author: User

Reprint Address: http://www.myhack58.com/Article/60/61/2014/50632.htm
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 () for PHP security has a lot of damage, so generally do not use the case in order to prevent similar to the following sentence Trojan invasion, need to prohibit!

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

Eval () Usage Example:

<?php
$string = ' Cup ';
$name = ' coffee ';
$str = ' This $string contains $name .<br> ';
Echo $str;
Eval ("$str =" $str ";");
Echo $str;
?>

The return value for this example is:

The $string is fitted with a $name.
The cup is filled with coffee.

Or more advanced points are:

<?php
$str = "Hello World"; For example, this is a meta-calculation.
$code = "Print (' n$strn ');"; /This is the PHP code stored in the database
Echo ($code);//After printing the combined command, the STR string is substituted, forming a full PHP command, but is not executed
eval ($code);//execute this command.
?>

For an example of the above coffee, in Eval, the string was replaced first, followed by a complete assignment command that was executed after replacing.

This kind of pony hit the door of the situation is to be banned!
However, many online say that using disable_functions to prohibit the Eval method is wrong!
In fact, Eval () is not allowed in the php.ini disable_functions:
Because Eval () is a language construct and not a function

Eval is Zend and therefore not a php_function function;

So how does PHP prohibit eval?

If you want to disable eval, you can use PHP's extension suhosin:
After installing Suhosin in php.ini load comes in suhosin.so, plus suhosin.executor.disable_eval = on can!

To summarize, PHP's eval function cannot be disabled in PHP, so we only use plugins!

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

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.