URL Pass Chinese character, special dangerous character solution (for reference only) UrlDecode, Base64_encode

Source: Internet
Author: User
Tags sql injection

Many times, we need to pass in the URL of the Chinese character or other special characters such as HTML, there always seems to be a variety of chaos, different browsers for their coding is not the same,

For Chinese, the general practice is:

Before passing the text string to the URL, first urlencode ($text);

But for some very "dangerous" characters, such as HTML characters, or even SQL injection-related characters, if it is clearly passed to the system, the system will generally filter them out for security reasons.

Now, we need these dangerous characters to do this.

My idea is to encode them Base64_encode ($text) First and then decode them Base64_decode ($text) to the server.

Seemingly perfect, but in the process of using a problem, Base64_encode encoded string contains "/", "+", "=" and other characters,

These characters in the URL encoding is a special character, such as "+", it means "space", but different browsers to "space" coding is not the same, some use "+" said, some use "20%" said, that is, let these base64_ The encode encoded string is passed in the URL, and the server gets a different value when browsing through the browser.

Thus, the idea of a compromise, the first of these Base64 encoded special characters replaced, to the service side, and then replaced back:

1 2 3 4 5 6 7 8 9 function  base_encode ($str) {          $src    =  Array ("/", "+", "=");          $dist   =  Array ("_a", "_b", "_c");          $old    =  base64_encode ($STR);          $new    =  str_replace ($src, $dist, $old);

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.