国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
字符串在傳遞過程中發(fā)生了變化,字符串傳遞
Home php教程 php手冊 字符串在傳遞過程中發(fā)生了變化,字符串傳遞

字符串在傳遞過程中發(fā)生了變化,字符串傳遞

Jun 13, 2016 am 08:51 AM
transfer front end Variety character string Condition enter

字符串在傳遞過程中發(fā)生了變化,字符串傳遞

情況描述:

  前端輸入的內(nèi)容是:;?9W/U\|"s6u|:M

  然而傳遞到后端再保存到數(shù)據(jù)庫時就成了:;?9W/U|"s6u|:M

這是為什么呢?

  這是怎么回事呢?

  1:我發(fā)現(xiàn)在insert到數(shù)據(jù)庫之前都還是正確的

  2:然后單獨使用heidisql工具去更改這個值,它顯示的sql語句是:

<code><span class="sql1-reservedword">  UPDATE<span class="sql1-space"> <span class="sql1-delimitedidentifier">`bitstorm_http_node`<span class="sql1-symbol">.<span class="sql1-delimitedidentifier">`config_user_pwd`<span class="sql1-space"> <span class="sql1-reservedword">SET<span class="sql1-space"> <span class="sql1-delimitedidentifier">`Password`<span class="sql1-symbol">=<span class="sql1-string">';?9W/U\\|"s6u|:M'<span class="sql1-space"> <span class="sql1-reservedword">WHERE<span class="sql1-space">  <span class="sql1-delimitedidentifier">`Id`<span class="sql1-symbol">=<span class="sql1-number">14<span class="sql1-symbol">;
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code>

  我們發(fā)現(xiàn)程序在insert操作之前,它在值中添加了轉(zhuǎn)義付去轉(zhuǎn)義特殊符號'\'

  可以究竟為什么會轉(zhuǎn)義?難道是字符串的單引號雙引號在作祟嗎?

  如果把字符放在單引號'之間,除了單引號本身'之外的絕大多數(shù)字符會解釋成和寫在代碼中一樣的形式。

  放在雙引號之間的字符串支持插入替換(內(nèi)嵌在字符串中的變量會被替換成其內(nèi)容),而且也會替換轉(zhuǎn)義字符,例如用換行符替換\n,用tab替換\t,\換成\\。同樣,\|它會解釋成|

  如果把上面的PHP中的代碼的sql置于單引號中,則會是無效的sql語句:

  Invalid query

  INSERT INTO `bitstorm_http_node`.`config_user_pwd` (`Id`, `Domain_Name`, `Username`, `Password`) VALUES (0, "mdc-mon-tg-zabvip01.ubisoft.onbe", "cheng.wang", ";?9W/U\|"s6u|:M");

解決辦法:

  在PHP中:并不是每一段被轉(zhuǎn)義的數(shù)據(jù)都要插入數(shù)據(jù)庫的,如果所有進入 PHP 的數(shù)據(jù)都被轉(zhuǎn)義的話,那么會對程序的執(zhí)行效率產(chǎn)生一定的影響,會產(chǎn)生性能問題。

  在運行時調(diào)用轉(zhuǎn)義函數(shù)(如 addslashes())更有效率。

  所以很明顯,這里插入數(shù)據(jù)庫我們需要轉(zhuǎn)義,所以在需要轉(zhuǎn)義的地方調(diào)用addslashes()函數(shù)來手動轉(zhuǎn)義即可

       <span>$pwd</span> = <span>addslashes</span>(<span>$pwd</span><span>);/<span><strong><span>/加這行代碼后保存到數(shù)據(jù)庫就對了,OK,解決問題
        </span></strong></span></span><span>if</span>(<span>$zabbixHelper</span>==<span>false</span><span>){
            </span><span>return</span> <span>$this</span>->returnError("Invalid input: Can not login zabbix using this username and password."<span>);
        }
        </span><span>$sql</span> = "INSERT INTO `bitstorm_http_node`.`config_user_pwd` (`Id`, `Domain_Name`, `Username`, `Password`) VALUES (0, '" . <span>$domainName</span> . "', '" . <span>$username</span> . "', '" . <span>$pwd</span> . "');"<span>;
        </span><span>$this</span>->callSqlQuery(<span>$sql</span>));

?

  最后,在PHP中,有時候json編碼后也需要轉(zhuǎn)義:

????? $parameters = addslashes(json_encode($args));

?

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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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)

PHP and Vue: a perfect pairing of front-end development tools PHP and Vue: a perfect pairing of front-end development tools Mar 16, 2024 pm 12:09 PM

PHP and Vue: a perfect pairing of front-end development tools. In today's era of rapid development of the Internet, front-end development has become increasingly important. As users have higher and higher requirements for the experience of websites and applications, front-end developers need to use more efficient and flexible tools to create responsive and interactive interfaces. As two important technologies in the field of front-end development, PHP and Vue.js can be regarded as perfect tools when paired together. This article will explore the combination of PHP and Vue, as well as detailed code examples to help readers better understand and apply these two

How to repeat a string in python_python repeating string tutorial How to repeat a string in python_python repeating string tutorial Apr 02, 2024 pm 03:58 PM

1. First open pycharm and enter the pycharm homepage. 2. Then create a new python script, right-click - click new - click pythonfile. 3. Enter a string, code: s="-". 4. Then you need to repeat the symbols in the string 20 times, code: s1=s*20. 5. Enter the print output code, code: print(s1). 6. Finally run the script and you will see our return value at the bottom: - repeated 20 times.

Exploring Go language front-end technology: a new vision for front-end development Exploring Go language front-end technology: a new vision for front-end development Mar 28, 2024 pm 01:06 PM

As a fast and efficient programming language, Go language is widely popular in the field of back-end development. However, few people associate Go language with front-end development. In fact, using Go language for front-end development can not only improve efficiency, but also bring new horizons to developers. This article will explore the possibility of using the Go language for front-end development and provide specific code examples to help readers better understand this area. In traditional front-end development, JavaScript, HTML, and CSS are often used to build user interfaces

Detailed explanation of the method of converting int type to string in PHP Detailed explanation of the method of converting int type to string in PHP Mar 26, 2024 am 11:45 AM

Detailed explanation of the method of converting int type to string in PHP In PHP development, we often encounter the need to convert int type to string type. This conversion can be achieved in a variety of ways. This article will introduce several common methods in detail, with specific code examples to help readers better understand. 1. Use PHP’s built-in function strval(). PHP provides a built-in function strval() that can convert variables of different types into string types. When we need to convert int type to string type,

Questions frequently asked by front-end interviewers Questions frequently asked by front-end interviewers Mar 19, 2024 pm 02:24 PM

In front-end development interviews, common questions cover a wide range of topics, including HTML/CSS basics, JavaScript basics, frameworks and libraries, project experience, algorithms and data structures, performance optimization, cross-domain requests, front-end engineering, design patterns, and new technologies and trends. . Interviewer questions are designed to assess the candidate's technical skills, project experience, and understanding of industry trends. Therefore, candidates should be fully prepared in these areas to demonstrate their abilities and expertise.

Detailed explanation of Golang string modification: dynamic adjustment and variability Detailed explanation of Golang string modification: dynamic adjustment and variability Apr 08, 2024 pm 03:27 PM

Strings in GoLang, although immutable, can be dynamically modified using the following technique: concatenating strings using string concatenation. Create a new string using string formatting. Modify the underlying byte slice of the string. Use mutable string types provided by third-party libraries.

Combination of Golang and front-end technology: explore how Golang plays a role in the front-end field Combination of Golang and front-end technology: explore how Golang plays a role in the front-end field Mar 19, 2024 pm 06:15 PM

Combination of Golang and front-end technology: To explore how Golang plays a role in the front-end field, specific code examples are needed. With the rapid development of the Internet and mobile applications, front-end technology has become increasingly important. In this field, Golang, as a powerful back-end programming language, can also play an important role. This article will explore how Golang is combined with front-end technology and demonstrate its potential in the front-end field through specific code examples. The role of Golang in the front-end field is as an efficient, concise and easy-to-learn

PHP String Operation: Remove Extra Commas and Keep Only Commas Implementation Tips PHP String Operation: Remove Extra Commas and Keep Only Commas Implementation Tips Mar 28, 2024 pm 03:02 PM

PHP String Operation: Remove Extra Commas and Keep Only Commas Implementation Tips In PHP development, string processing is a very common requirement. Sometimes we need to process the string to remove extra commas and retain the only commas. In this article, I'll introduce an implementation technique and provide concrete code examples. First, let's look at a common requirement: Suppose we have a string containing multiple commas, and we need to remove the extra commas and keep only the unique comma. For example, replace "apple,ba

See all articles