In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to solve the problem of url transmitting Chinese characters and special dangerous characters in php. It is very detailed and has a certain reference value. Interested friends must finish reading it!
We need to pass Chinese characters or other special characters such as html in url. There always seems to be a lot of confusion, and different browsers have different codes for them.
For Chinese, the general practice is:
Urlencode ($text) these text strings before passing them to url
But for some very "dangerous" characters, such as html characters, or even SQL injection-related characters, if they are obviously passed to the system, the system will generally filter them out for security reasons.
Now, we need these dangerous characters, what should we do?
What I can think of is to encode them with base64_encode ($text) first, and then decode them with base64_decode ($text) when they get to the server.
It seems perfect, but there is another problem in the process of using it. The string encoded by base64_encode contains "/", "+", "=" and other characters.
The base64_encode () function passes user input views (a small amount of content) in url, and when the user submits (post submits), it is an array. So I encrypt my point of view with the bse64_encode () function. When I jump to the processing page, I send it to get, and the encrypted data on both sides is incorrect. A + character is missing.
User submits encryption:
TPK9tNPNyKUsuse6xyYjNDY7JiM0NjsufMavwcEhfMyrxq/BwcHLLMjDztLO3tPvLNXmz+vI69ehsKEhfHw=
Received with get on the processing page:
TPK9tNPNyKUsuse6xyYjNDY7JiM0NjsufMavwcEhfMyrxq/BwcHLLMjDztLO3tPvLNXmz vI69ehsKEhfHw=
Comparison found a lack of a plus sign, I do not know why the system (guess may be get, the + character may not be able to get it!). Also ask the expert to give us some advice.
These characters are also special characters in url coding, such as "+", which represents "space", but different browsers have different encoding of "space", some using "+" or "20%", that is to say, let these base64_encode-encoded strings be passed in url, and when browsing with different browsers, the server gets different values.
As a result, we came up with a compromise: replace these base64-encoded special characters, and then replace them back to the server:
Solution:
one。 When the user submits the encrypted string, I replace the + character with another character. For example: str_replace ('+','_', $content)
two。 Convert again on the processing page: for example: str_replace ('_','+', $content)
The copy code is as follows:
Function base_encode ($str) {
$src = array ("/", "+", "=")
$dist = array ("_ a", "_ b", "_ c")
$old = base64_encode ($str)
$new = str_replace ($src,$dist,$old)
Return $new
}
Function base_decode ($str) {
$src = array ("_ a", "_ b", "_ c")
$dist = array ("/", "+", "=")
$old = str_replace ($src,$dist,$str)
$new = base64_decode ($old)
Return $new
}
Here is the effect you get in the browser
XOO6w6Osuf65_aiy_atL_b00Ke5_b8jnus6ho6GjoaM_c
The urldecode instance method is very simple
Urldecode (string $str)
Decode any% # # in the encoded string given. Returns the decoded string.
Example # 1 urldecode () example
The copy code is as follows:
The above is all the contents of this article entitled "how to solve the problem of url transmitting Chinese characters and Special dangerous characters in php". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.