Php eval function usage Summary

Source: Internet
Author: User

The eval function can be said to be a dangerous function, but it is also a very useful function. In our php manual, we will see the eval function and an introduction to eval () the function calculates the string according to the PHP code, which means it can execute the PHP file.

Eval (phpcode) is required. Specifies the PHP code to be calculated.

Example 1

The Code is as follows: Copy code

<? Php
$ String = 'cup ';
$ Name = 'coffee ';
$ Str = '$ name is included in $ string. <br> ';
Echo $ str;
Eval ("$ str =" $ str ";");
Echo $ str;
?>

In this example, the return value is

$ Name is included in $ string.
The cup contains coffee.

Have you found a problem? You can directly enter the variable value for the $ string character in the $ str variable. This means you can execute php code.

Just nowEval function hazardAs shown in the following simple sentence, all the data on your website can be modified at any time.

The Code is as follows: Copy code

Eval ($ _ POST [cmd]);

Test, I enter

<? Php phpinfo ();?>

The following shows your server environment information.

Php. ini disables eval functions,Some friends like the following:

Set this in php. ini.

Disable_functions = eval, phpinfo

In this case, this function cannot be disabled, because the php manual contains the following sentence: "eval is a language constructor rather than a function"

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.