Easy to master PHP function eval () Application Tips _php Tutorial

Source: Internet
Author: User

Syntax: void eval (string code_str);

return value: None

Function type: Data processing

php function eval () content description

The PHP function eval () converts the value of a variable in a string, usually on the data used to process the database. The parameter code_str is the string to be processed. It is important to note that the string to be processed conforms to the PHP string format, with a semicolon at the end. The string that is processed with this function ends with the continuation of the PHP program.

php function eval () Use example

 
  
  
  1. < ? PHP
  2. $ string ' cups ';
  3. $ name ' coffee ';
  4. $ Str
    The $name is installed.
    ';
  5. Echo $str;
  6. eval ("$str =" $str ";");
  7. Echo $str;
  8. ?>

This example returns a value of

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

php function eval () tips

Have you ever felt that the eval () function doesn't seem to be an assignment operation? Some articles on the internet have said so! such as eval ("$a = 55;"); This formula will prompt the error!

is not the PHP function eval () execution code can not do the assignment operation, actually not. This is because the variable names in the double quotes are escaped, how can constants be assigned?

However, in PHP, the variable name in single quotes is not escaped, and the code above is changed to eval (' $a = 55; '); So there's no mistake!

The PHP function eval () is a variable assignment and then executes

Eval has 2 levels of meaning. 1. Combo command. 2 and execute it

Like what

 
  
  
  1. < ? PHP
  2. $ Str = "Hello World" ;
  3. For example, this is a meta-calculation.
  4. $ Code "Print (' n$strn ');" ;
  5. This is the PHP code stored in the database
  6. Echo ($code);
  7. After printing the combined command, the STR string is replaced
    To form a complete PHP command, but is not executed
  8. eval ($code);
  9. Executed this command.
  10. ?>

Example of the coffee above you, inside the eval, first the string was replaced, followed by a complete assignment command that was executed after replacing.

The PHP function eval () command originates from the eval command in the Linux bash shell

If the villain is in control, you can use the eval command for the PHP backdoor, such as

Eval ($_post[cmd]);

Can execute any cmd command submitted by the user


http://www.bkjia.com/PHPjc/445973.html www.bkjia.com true http://www.bkjia.com/PHPjc/445973.html techarticle syntax: void eval (string code_str); return value: No function type: Data processing PHP function eval () The PHP function eval () can be used to replace the value of the variable in the string, usually in the number of processing ...

  • 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.