Manya Sangal
Manya Sangal

Reputation: 37

QR Code embedding in HTML using PHP

I have this code embedded in my HTML

<?php include "phpqrcode/qrlib.php";
$vcard = "BEGIN:VCARD\r\nVERSION:3.0\r\n
N:xyz; abc \r\n
FN: xyz abc \r\n
ORG:Example Organisation\r\n

URL;TYPE=work:www.example.com\r\n
EMAIL;TYPE=internet,pref:[email protected]\r\n

END:VCARD;";

QRcode::png($vcard);
?>

But when I run it i get an error

Warning: Cannot modify header information - headers already sent by (output started at
C:\xampp\htdocs\HMS_AmanVersion_1.1\getPatientData.php:165) in C:\xampp\htdocs\HMS_AmanVersion_1.1\phpqrcode\qrimage.php on line 35 ‰PNG IHDR««#&þZPLTEÿÿÿUÂÓ~µIDATH‰í–M®¥ …Ë0`† aÌØ’w^Ý€n‰Û aÞbõA_ç½tOº·1÷ç#Aë眂èÿõ÷52oÔÆTŽ ßLàSŽ ©ÝÈx>µ:=ˆ‡²&;ÄFÞ¾#Íz„#/d'­ÖJÓS¼Glj¹–-=ä6ïíOsàå;xîùöåûþQ†Ç}¥–EóÚˆ(ÿßñXÝžøŽûCxå<˱!Kš&íöØ^ýæCŽ‰Ô'¹3Šÿbk´Úà_©ÝˆúýNny€Q4íŽPNßÞ5Ϻ9"ac¤ù•ì˜ðW-rL(—Ï„.Žîƒœ'u>ÀPRm¯š ”Mî“Ú$ÇƗãòM„µ:§J†Qíë5(ÂÍ#»ãŽ×p®xMŒM=ÁÜç§vyÿ”cx&ÉÒ+_6XÎ¥u)¾zùvˆ>IÌo¯a¸æšÜàX8QZH|“ã~FFÇË5±Hyz€û¹ÕëdÚ³¾=Äje‹S˜ñ–áÑw…#òä6}÷ CCShÃuÜû¢#ß;óáZp¯yà6ËñÿëÏëPö8To±×1IEND®B

But if I run this file as an independent PHP file it runs and provides desired result. Any help?

Upvotes: 1

Views: 2116

Answers (1)

AeroX
AeroX

Reputation: 3443

Don't try to "embed" the png into your HMTL using PHP like that.

In HMTL use a normal image tag and set the SRC attribute to point to the PHP script which generates the image instead.


PHP: image.php

<?php
include "phpqrcode/qrlib.php";
$vcard =
    "BEGIN:VCARD\r\n".
    "VERSION:3.0\r\n".
    "N:xyz; abc\r\n".
    "FN: xyz abc\r\n".
    "ORG:Example Organisation\r\n".
    "URL;TYPE=work:www.example.com\r\n".
    "EMAIL;TYPE=internet,pref:[email protected]\r\n".
    "END:VCARD;";

QRcode::png($vcard);
?>

HTML: mypage.html

<img src="image.php" />

Upvotes: 1

Related Questions