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.