Incorrect QR code generation using phpqrcode

Source: Internet
Author: User
After receiving the data sent from the client, add the data as a parameter to the URL and generate the QR code for the URL. The QR code can be generated, but the URL of the generated QR code does not contain the parameters I want. The code is as follows {code ...} it is estimated that there is a problem when the parameter data transmission comes over, but I don't know how to arrange it... after receiving the data sent from the client, add the data as a parameter to the URL and generate the QR code for the URL. The QR code can be generated, but the URL of the generated QR code does not contain the parameters I want.

The code is as follows:

$ Param_str = urldecode ($ _ POST ['data']); $ param_str = base64_encode ($ param_str); $ url = "http://www.example/order_add.php? Data = ". $ param_str; // url1 is to write parameters directly into the URl // $ url1 =" http://www.example/order_add.php? Data = blank = "; // The data parameter in the link for generating the QR code is empty echo QRcode: png ($ url ); // This generates the correct QR code // echo QRcode: png ($ url1); // $ url is 1 compared with $ url1 constant, and both are encoded in ASCII format.

It is generally estimated that there is a problem when data transmission comes over, but I don't know how to troubleshoot it.

In addition, the correct QR code can be generated.

// Manually assign $ param_str = "required Sources = "; $ url =" http://www.example/order_add.php? Data = ". $ param_str; echo QRcode: png ($ url); // add a path to generate an object image file. if multiple users access the file at the same time, the former will be overwritten. Therefore, it is not suitable for actual use of QRcode: png ($ url, "order_qr.png ");*/

Reply content:

After receiving the data sent from the client, add the data as a parameter to the URL and generate the QR code for the URL. The QR code can be generated, but the URL of the generated QR code does not contain the parameters I want.

The code is as follows:

$ Param_str = urldecode ($ _ POST ['data']); $ param_str = base64_encode ($ param_str); $ url = "http://www.example/order_add.php? Data = ". $ param_str; // url1 is to write parameters directly into the URl // $ url1 =" http://www.example/order_add.php? Data = blank = "; // The data parameter in the link for generating the QR code is empty echo QRcode: png ($ url ); // This generates the correct QR code // echo QRcode: png ($ url1); // $ url is 1 compared with $ url1 constant, and both are encoded in ASCII format.

It is generally estimated that there is a problem when data transmission comes over, but I don't know how to troubleshoot it.

In addition, the correct QR code can be generated.

// Manually assign $ param_str = "required Sources = "; $ url =" http://www.example/order_add.php? Data = ". $ param_str; echo QRcode: png ($ url); // add a path to generate an object image file. if multiple users access the file at the same time, the former will be overwritten. Therefore, it is not suitable for actual use of QRcode: png ($ url, "order_qr.png ");*/

I answered the question by myself. I only found the error and did not find the cause.
This problem occurs when the client uses JQuery $. the parameters passed by ajax make phpqrcode unable to be obtained (data is indeed obtained on the server side, and the url of phpqrcode is correct before encoding ), the client can use form submission instead.

Urldecode is not required for jquery ajax operations. In fact, urlencode is generally used, and the browser automatically decode.
Check whether the parameter is missing due to this reason.

Related Article

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.