PHP function Base64_encode After the argument contains the plus sign parsing error solution

Source: Internet
Author: User

Before entering the topic, let's take a look at the following code, test.php

<?php$url = "Test2.php?name=". Base64_encode (' The string used to do the test '). " &age=23 "; Header (" Location: $url ");


test2.php

<?phpvar_dump (Base64_decode ($_get[' name '));d ie ();

When accessing http://localhost/test.php addresses, redirect to http://localhost/test2.php?name=55so5p2l5yga5rwl6k+v55qe5a2x56ym5liy& age=23 address, the browser outputs the result:

string ' To do the test? ' Y?? 9ke??)?., '(length=26)

What's going on, Base64_decode can't decode?


Careful observation of the redirected address after the encryption of the name parameter, which contains the "+" symbol, and the browser address bar encountered "+" symbol will be converted to a space, so to ensure that the correct decoding operation Base64_decode, we can first replace the space in the parameter Chengga number, As shown in the following code:

<?php$replaces = Array (' = = ' + '), Var_dump (Base64_decode (STRTR ($_get[' name '), $replaces)));d ie ();
Get the correct output result:

string ' The string used to do the test ' (length=27)



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

PHP function Base64_encode After the argument contains the plus sign parsing error solution

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.