1

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:xyz@manya.com\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?

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Amal Murali Mar 11 '14 at 12:07

1 Answers1

1

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:xyz@manya.com\r\n".
    "END:VCARD;";

QRcode::png($vcard);
?>

HTML: mypage.html

<img src="image.php" />
AeroX
  • 3,387
  • 2
  • 25
  • 39