Home Backend Development PHP Tutorial Instructions for using the php get_magic_quotes_gpc() function

Instructions for using the php get_magic_quotes_gpc() function

Jul 06, 2017 am 11:12 AM
magic quotes Instructions for use

get_magic_quotes_gpcThe function is used to determine whether to add slashes to the data provided by the user. This is in the php.iniconfig file. This article will introduce get_magic_quotes_gpc() Function description. Let's take a look at it with the editor

The get_magic_quotes_gpc function is used to determine whether to add slashes to the data provided by the user. This is in the php.ini configuration file. Let me introduce get_magic_quotes_gpc( ) Function description.

get_magic_quotes_gpc function introduction

Get the value of the PHP environment variable magic_quotes_gpc, which is a PHP system function.

Syntax: long get_magic_quotes_gpc(void);

Return value: long integer

This function obtains the value of the variable magic_quotes_gpc (GPC, Get/Post/Cookie) of the PHP environment configuration . Returning 0 means turning off this function; returning 1 means turning this function on.

When magic_quotes_gpc is turned on, all ' (single quotes), ” (double quotes), (backslashes) and null characters will automatically be converted to overflow characters containing backslashes.

magic_quotes_gpc Sets whether to automatically add backslashes to '" in the data sent by GPC (get, post, cookie). You can use get_magic_quotes_gpc() to detect system settings.

If this setting is not turned on, you can use the addslashes() function to add it. Its function is to add backslashes before certain characters when required in database query statements.

These characters are single quotes ('), double quotes ("), backslash () and NUL (NULL character).

By default, the PHP instruction magic_quotes_gpc is on, it Mainly to automatically run addslashes() on all GET, POST and COOKIE data.

Do not use addslashes() on strings that have been escaped by magic_quotes_gpc, because this will cause double-level escaping. In this case, you can use the function get_magic_quotes_gpc() for detection

Example

The correct way to use get_magic_quotes_gpc() to prevent database attacks##.

#The code is as follows

<?php
function check_input($value)
{
// 去除斜杠
if (get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// 如果不是数字则加引号
if (!is_numeric($value))
{
$value = “‘” . mysql_real_escape_string($value) . “‘”;
}
return $value;
}
$con = mysql_connect(“localhost”, “hello”, “321″);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
// 进行安全的 SQL
$user = check_input($_POST[&#39;user&#39;]);
$pwd = check_input($_POST[&#39;pwd&#39;]);
$sql = “SELECT * FROM users WHERE
user=$user AND password=$pwd”;
mysql_query($sql);
mysql_close($con);
?>
Copy after login

The summary is as follows:

##1. For the case of magic_quotes_gpc=on,

We can not perform

addslashes() and stripslashes() operations on the string data of the input and output databases, and the data will be displayed normally

If you do this at this time. The input data has been processed by addslashes(),

then you must use stripslashes() to remove excess backslashes when outputting

2. For magic_quotes_gpc=off. Situation

You must use addslashes() to process the input data, but you do not need to use stripslashes()

Format the output

Because addslashes() does not Writing the backslashes together into the database just helps mysql complete the execution of the sql statement

The above is the detailed content of Instructions for using the php get_magic_quotes_gpc() function. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Learn about Magic Eden's Diamond Rewards: Value Earned and How to Get It Learn about Magic Eden's Diamond Rewards: Value Earned and How to Get It Jan 26, 2024 pm 05:57 PM

Previously, MagicEden, a mainstream NFT market on the SOL chain, launched the Launchpad function. Prior to this, PANews has introduced the operating status of MagicEden and provided analysis on optimizing operating methods and investment methods for NFT trading platforms and users. Recently, MagicEden launched new activities in terms of operations and introduced diamond rewards to motivate users to use its products. In this article, PANews will explain in detail how to get MagicEden’s diamond reward and evaluate whether this reward is worth earning. Are MagicEden Diamond Rewards worth earning? According to the official blog, the MagicEden platform now offers users more long-term benefits through Diamond Rewards empowerment.

The largest foldable external screen! Honor Magic V Flip unveiled The largest foldable external screen! Honor Magic V Flip unveiled Jun 14, 2024 am 11:21 AM

According to news on June 13, today evening, Honor’s first small folding screen Honor Magic VFlip officially debuted. Different from other small foldables, Honor MagicVFlip brings the industry's largest vertically folding magic external screen. Its screen size is 4.0 inches, using a four-curved and equal-depth design. The screen-to-body ratio has reached an unprecedented 85%. From then on, the external screen is no longer The "secondary screen" is the main screen both inside and outside. At the same time, Honor MagicVFlip external screen also has screen quality comparable to flagships, industry-leading Honor eye protection screen, and full-scenario smart interaction. It is reported that the Honor MagicVFlip external screen is a global low-power LTPO external screen that achieves an industry-leading local peak brightness of 2500nit.

Can magic system be upgraded to Hongmeng? Can magic system be upgraded to Hongmeng? Dec 22, 2022 pm 02:29 PM

The magic system cannot be upgraded to Hongmeng, because the magic system belongs to Honor phones, and Honor has been separated from Huawei and is no longer a subsidiary of Huawei. Therefore, Honor phones released after November 17, 2020 do not support upgrading to Hongmeng. systematic.

Zhao Ming warms up the Honor Magic V3: challenging the new height of foldable screen thinness and lightness Zhao Ming warms up the Honor Magic V3: challenging the new height of foldable screen thinness and lightness Jun 26, 2024 pm 03:51 PM

According to news on June 26, today, at the Shanghai MWC, Honor CEO Zhao Ming announced that Honor Magic V3 will be launched soon. This new product will challenge the new realm of foldable screens and thinness. Zhao Ming said that 12 months after the release of Honor MagicV2, no one has broken the record of thinness and lightness. Only Honor can surpass Honor. In July last year, the Honor MagicV2 had a folded thickness of only 9.9mm, an unfolded thickness of 4.7mm, and a weight of 231g. It broke the boundary between a candy bar machine and a folding screen, because when closed, it was almost as thick as a candy bar machine. and weight. It is reported that Honor MagicV2 uses the latest components such as screen, PU material, hinge, heat dissipation system, antenna, Type-C interface, fingerprint recognition, speakers, etc.

How to use OnePlus budsPro_OnePlus budsPro instructions How to use OnePlus budsPro_OnePlus budsPro instructions Mar 23, 2024 am 10:11 AM

1. Switch between noise reduction mode and transparency mode. Press and hold the handle of the earphones for about 1 second to switch between noise reduction mode and transparency mode. 2. In music mode, press the earphone handle once to pause or play music. Press the earphone handle twice to play the next song. Press the earphone handle three times to play the previous song or wake up the voice. 3. In call mode, during a call, press the earphone handle once to answer or hang up the call. 4. How to reset Open the earphone box. When the charging box indicator light flashes red 5 times, release the button and the earphones are reset. 3. How to connect the phone 1. Open the charging box 2. Press and hold the setting button for 2 seconds 3. When a pop-up window appears on the phone screen, click to confirm the connection. 4. How to check the battery status 1. When the earphones are connected to the mobile phone, you can check the battery level of the earphones and charging box in the pop-up window on the mobile phone screen. 2,

Instructions for accessing and using the payment function of UniApp Instructions for accessing and using the payment function of UniApp Jul 04, 2023 am 10:27 AM

Instructions for accessing and using the payment function of UniApp. With the popularity of mobile payment, many applications need to integrate payment functions to facilitate users to make online payments. As a cross-platform development framework based on Vue.js, UniApp has the characteristics of one-time development and multi-platform use, and can easily implement the payment function. This article will introduce how to access the payment function in UniApp and give code examples. 1. To access the payment function, add payment permissions in the manifest.json file on the App side:

How to use the video recording function in uniapp How to use the video recording function in uniapp Jul 06, 2023 pm 06:51 PM

How to use the video recording function in uniapp Today, the author will introduce to you how to use the video recording function in the uniapp development framework. uniapp is a cross-platform development framework. We can run our applications on multiple platforms at the same time based on the code written once, which is very convenient for developers. In uniapp, we can use the uni-AD-IN camera component to implement the video recording function. First, we need to install uni-

How to use the Hyperf framework for multilingual processing How to use the Hyperf framework for multilingual processing Oct 20, 2023 am 11:10 AM

How to use the Hyperf framework for multi-language processing Introduction: With the globalization of the Internet, multi-language processing has become an essential skill for the development of many applications. In web application development, it is very important to be able to support multiple languages ​​because it can help you better meet the needs of different users. This article will introduce how to use the Hyperf framework for multi-language processing and provide specific code examples. Install the Hyperf framework First, we need to install the Hyperf framework. You can use the composer command to

See all articles