Basic php knowledge (1)-Magic reference

Source: Internet
Author: User
Php Basics (1)-Magic reference php Basics-magic reference sample code download page http://xieye.iteye.com/blog/1336095 (in Attachment) Magic reference refers to: the server automatically converts some characters, to facilitate the programmer's practice. Source: In the beginning, php designers added the basic php knowledge (1)-Magic reference in the configuration file to help programmers add form data to the database.
Php Basics-magic reference

Sample Code Download page http://xieye.iteye.com/blog/1336095 (in attachment)

Magic reference means that the server automatically converts some characters to facilitate the programmer's practice.

Source: In the beginning, php designers added a setting in the configuration file to facilitate programmers to add form data to the database. when the option is enabled, Magic reference is enabled. when the option is disabled, magic reference is not enabled.

Php. ini contains about 441 rows.
Magic_quotes_gpc = Off
Annotation is; Magic quotes for incoming GET/POST/Cookie data.
Note: If it is on, the get/post/cookie data that enters the server is automatically converted.

1) addslashes function
Before introducing magic reference, we will first introduce the addslashes function

This function returns a string that requires a backslash before certain characters for database query statements. These characters are single quotation marks ('), double quotation marks ("), backslash (\), and NUL (NULL ).

An example of using addslashes () is when you want to input data into the database. For example, insert the name 'Reilly into the database, which requires escaping. Most databases use \ as the escape character: O \ 'Reilly. In this way, the data can be put into the database without inserting additional \. When the PHP command magic_quotes_sybase is set to on, it means that when 'is inserted,' is used for escape.

By default, the PHP command magic_quotes_gpc is on, which automatically runs addslashes () on all GET, POST, and COOKIE data (). Do not use addslashes () for strings that have been escaped by magic_quotes_gpc, because this causes double-layer escape. In this case, you can use the get_magic_quotes_gpc () function for detection.

Example 1. addslashes () example
Http: // localhost/command/peixun/magicquote/1.php
 

2) test the configuration option magic_quotes_gpc
First, make sure that magic_quotes_gpc = On. if it is off or 0, modify it and restart the apache server.
Http: // localhost/command/peixun/magicquote/2.php
            longs;    echo $html;    } else {    echo $_POST['name1'];    }

Modify magic_quotes_gpc = Off, restart the apache server, and test the program again.

It should be noted that these are all learning concepts. In most practical applications, Magic reference is disabled and manual conversion is performed.




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.