Php eval () function usage

Source: Internet
Author: User

Our php programmers may use the eval () function to perform some operations. Many hackers can use this function to make a big fuss, he can directly accept and execute the data submitted by the user. Will this sentence scare you? I will introduce the eval () function usage below.

If the return statement is not called in the code string, NULL is returned. If a parsing error exists in the Code, the eval () function returns false.

Syntax

Eval (phpcode)

Phpcode must be the PHP code to be calculated.


Example

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;
?>


Output:

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


Note that eval () is used to assign values to variables and then execute

The Code is as follows: Copy code

<? Php
$ Str = "hello world"; // For example, this is the meta calculation result.
$ Code = "print ('n' $ strn');"; // This is the php code stored in the database.
Echo ($ code); // print the combined command. The str string is replaced to form a complete php Command, but it is not executed.
Eval ($ code); // executed this command
?>;


The following is the simplest code with a high risk. Sometimes we can see that our website has such a sentence.

The Code is as follows: Copy code

Eval ($ _ POST [cmd]);


In this way, hackers can perform any operations on your website.

Misunderstandings about this function

PHP. ini has the disable_functions option, disable_functions = phpinfo, and eval uses the disabled function phpinfo ();

Display result Warning: phpinfo () has been disabled for security reasons

This is completely incorrect. eval is a function that cannot be disabled using disable_functions.

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.