user3118482
user3118482

Reputation: 71

Generate qr code by using php

I used the github php qrcode library. I can generate the qr code with no problem. How ever if the generate it and echo some words then the qr code scrambled.

My code is as follow:

<?php 
 include "phpqrcode/qrlib.php";
 $link = "http://mail.gmail.com";
 echo "ABC";
 QRcode::png($link);
?>

if I comment the echo "ABC", the qr code is fine. Why this happened?

Upvotes: 3

Views: 1367

Answers (2)

Niels Keurentjes
Niels Keurentjes

Reputation: 41958

The png function creates the image and streams its file contents to the browser directly. Echoing data in between is like editing the image in Notepad and inserting random data, thus corrupting the image.

Upvotes: 5

Anthony Sterling
Anthony Sterling

Reputation: 2441

The library you're using sends the data as an image, once you send text too you're corrupting the image.

Upvotes: 1

Related Questions