captcha works good in my localhost usbwebserwer. In web serwer captcha image not showing. when open image in firefox see code:
ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC $.' ",#(7),01444'9=82<.342ÿÛC 2!!22222222222222222222222222222222222222222222222222ÿÀ(x"ÿÄ ÿĵ}!1AQa"q2‘¡#B±ÁRÑð$3br‚ %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵw!1AQaq"2B‘¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÚ?õ{¥Ãgieg§ìmNÞ8a¶É,aË’\)ùNðK|Äv‘Y“X˪¨ÚÜÛB-£•bx¥hB³ 1æo¼r褟˜°©5Ý&ÊËJ¶Õ, Ħ‚â#åZ G1rýÅR9þš²'K›h,®ôíÿe„ùÊЋ€Ê#Ü#VÄ[É*ÊÌJ3}ìŽè$õ‹þ¿«·Ü»iâ´i¦öm>í§G–cöh2°“ºÊã+Ø6rß=mÙjÚÌsMoyáÃ[2q9$ÈÇ;T« ¤6îBõÀ–íõ ¤–Ár]ÝÅŵ¯rñ’ª r2#áñÔ»tÒEoy¨Ío-¾£Ôb`æI¼éV6¨œ,ƒ¹¹#¤ï;Y‰Ev³ûÄ™·M¨¾¡x.nÙ‘ÙÑ>Ð]b(~##•q’¤3§Êq¸Ö$šd–1ßé–÷×+o:ÚÞ¢LŒxm¹Sµ6»+1'0, Œ·x}üS«Ú]\Zx²k1l‹Iµ ‘¤Y‚ \ð0#ÎXõé“ÇumðÒyn¼Eo¨kš\Žã‰s2±.̸+´àrªày§k…îo¾±¨é–ñÞI»)+^.õŒ‡ÚƒpÃm?6NßšµÛ¤‚IþÉ"”DIH…Ö±„aÃdnbNÔ<¥¸ç~\6¡áë«ínöîP—rEï{(³*9¾X±Ë$ãïgåÜ›M¹²»Õ--îÚÈFmä†ÞRüË‘4{¨ ÇÏÆìàäÏ,Sqc»µËúŽ¥¡CmG%º`É°¬Ä«$jåU3*î<© #ÒŠhçŒÇeªÃ1Œ$ûñîL[s¿ ˜yJŒ3ç ÀSæ6¾#·ŸÇm*£œÊ%žûS±- +¿$«K7‚GžÍtó©ÜØËka¤ÄâÜËöu%Šg#Ê #‘Ž¹â‰ÓJÉ°R¹½}z|w–6ØGiÓÉå¶ÐÊÛ‰\î8òÉwࣜTEå•õ¹â–9áO–A0ŒÆIhKd¬„Œœ8,\Œ¡h:-Œ’_Ì€ÆU/†ô*w`˜Â»pf ±n 2ƒE†“syT;eÈ‘ŒäžTœ’<Ö‰/õtoÊXeÒî´É'b‡toóR1¸‰$ÈCŸâÚÙ´5KúìKÜóøNóÅþ ¼ zÑVqPÆ¥¤c´þôƒ¼¯ ýÆÀ'öZ„5mË£~÷ê#co=¡Rˆ¬¤*ùóù$ƒµ6’wgå5¾^\¯…,¡B^MBYSæزmXò¥„ŠxÎHÚã;N®³Tׯ/í5Ý;O™|¼D%V 䃂ü—8U_˜åˆSZÊsç²Ø„•Ó´¯XØj¶Öò^é±Z#×WVí#ÂdNÊÿÕÒé3Oâk½ìw×·©o4~h‘JÄK4ŒêGÝ#ävùMsÚÖ²ðëN&ôn n,UŽB…ÉrH+×vyÎk²ÑYð×ÂÝ_L¸Ògß-Ïï#ÚѸ*r¯=1‡çŽ7í¦ä#‘м=©êÞ Ôï-.ŒZ4"¥Ä걇pÎÁ€ªBž¤Ÿök¦ð=æ£ÿ«j—eo-l¦6–ñ^š.B’ 3†\ÚNÀg‚ ¹O…ZõìqÀЫÝFï4 ÁµÁØ œ,ƒ åˆQ€2iŸÙŸÃr[‰´˜Þ;.‰p±Œå72°”$ð &Û¸ÒØåãðdòxí|+öØcˆQ<Ѽk“ð6°3ÐqÉ"½{ı\^økQÔ$±»‹PŽÎxå“dO´K0 å3† oâód„Ïû¶iI“ }ðF~SÂóŒƒCÂöžx‚êKe–ݨup) ®ÓÀ'-× }w[¢„h×rMm,ÂIÌAи?îÊnÙ¸àž‚Ê¸ÏÍŠ¬ÄŠ^ñ—ö^™áû=×(‘ÝÌ—& É Tpç3IÏnri|&Žy!Öu'6Èxƒ]Ïr}òÇÏ"í9aƒ†Î?ÁÙè]éÚíÔbVM0)BFYñÎËò«ž>\u"½Ÿáfœ–¾³êV³^Mæ#yJgV22(ÌAÜ« oñ¸ çYÆ1vëÿTnÙ¿¦ÝÜéÚEí¸¶½ÙG,¶Í$&$eRÌ»þD?À¹’ÞiÏ}¥^·ŠÞÒú{[};θTŽ|Ef±ÄŠTª†`œyy`‹EróÅ6ÜoøY÷ lÓ5t·?<vÕ2óæ#ù.!‚u¶9?u…[¤Ó^ßLÔ’HaÓ¢2¥±ù4„ã˜ÊìháŽåEEmëù e SÃÜÛI$:|¨îež8¬žXbF}æÄjHf%šNêMk‰î´ø>Ñ¥Ù[K¦ÊBºvÖÛ"ªà«ó`Pü¤½¸tRŠNMÙ=F—bÝÕ¬ïxñ4ùµdKHªù€ºC™U¼Ì…\ó‚pYys.£=šÄÚDÊR1=Éš}¹MÅBòpÛ~bëÈV%h¢³RÕÆDž¿¶‘-…ýíéÄ“òª‚ëóo#_rÎñ’¬AWªó˦è÷sD4…þÓR‰¹›#LJB’;t W9e'6ÇiEoJn£´»$–ÆÌwu©Ã;¼6qÞFÉ-µÄLî¨H 9)ó#iÛ÷ܱ&´f[ä™ná2I+¥Ï”#qI‡FyóÕÁ!ˆ¢³Ý¤2–™!Ô,£xå[Avñ}¤ ˜MªûAåz¨íÚ~`]¨X]É«!¼¹Ó>Á4ÌP«¾Ì!mÇsI’Tê:QE&í+!¥tC§ÙZ궖ªÑ[#‹P¢Ý ŠUŽDØ’Ì|°0~æA*jº´1³Ùÿiëˆäâ,†)nr<àåßÆÒ¤ÿt•V%¢Õ²KE{a|ÓÃr×PÜÀ²3B²yyEùOšXº®ÒAÕ™2QEJŠ–ã»[ÿÙ
Chrome calling:
Resource interpreted as Image but transferred with MIME type text/html
Here is code in my captcha:
<?php
/**
* #version 1.6.0
* #package Joomla
* #subpackage OS Membership
* #author Tuan Pham Ngoc
* #copyright Copyright (C) 2012 - 2013 Ossolution Team
* #license GNU/GPL, see LICENSE.php
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
class CaptchaSecurityImages
{
function generateCode($characters)
{
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters)
{
$code .= substr($possible, mt_rand(0, strlen($possible) - 1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6')
{
$session = JFactory::getSession();
$this->font = JPATH_COMPONENT . '/assets/font/monofont.ttf';
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for ($i = 0; $i < ($width * $height) / 3; $i++)
{
imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
}
/* generate random lines in background */
for ($i = 0; $i < ($width * $height) / 150; $i++)
{
imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4]) / 2;
$y = ($height - $textbox[5]) / 2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$session->set('osm_security_code', $code);
}
}
here HTML:
<div style="position:relative">
<input type="text" class="inputbox input-mini" value="" size="8" name="security_code">
<img src="/rejestracja-enterprise-kwartalnie?task=show_captcha_image" title="Please enter the code you see in the image into Security code textbox" align="middle" id="captcha_image">
<a class="osm_reload" href="javascript:reloadCaptcha();"></a>
</div>
That is the image. You're just not telling your browser that it is, your browser interprets the data as text. Set a header to tell your browser to interpret the data as image:
header('Content-Type: image/jpeg');
The image data will have to be the only thing output on the page, no other HTML or text before or after it.
Ref Link : php imagejpeg()
Try This
ob_start();
header( "Content-type: image/jpeg" );
imagejpeg( $image, NULL, 100 );
imagedestroy( $image );
$i = ob_get_clean();
echo "<img src='data:image/jpeg;base64," . base64_encode( $i )."'>"; //saviour line!
Related
I am developing an HTML user form where I am using a PHP captcha script:
<?php
session_start();
class CaptchaSecurityImages {
var $font = 'php/monofont.ttf';
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = #imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurityImages($width,$height,$characters);
?>
my form looks like:
it used to work like charm and all the sudden on form submission I am getting a frequent error that the user entered CAPTCHA doesn't match the picture,
Investigating further I found that: in chrome once I click any field in the form without typing the $_SESSION['security_code'] value was changed on on its own on the server and ofcourse the photo was never updated, investigating further I found that there are some eventlisteners were set in chrome by my Kaspersky which seems they were the root cause of the problem as they were querying the Captcha photo link once I click on the form and start type in any field before submission (They look like that:-
, please note that my HTML file doesn't use any javascript that could have cause such event firing, as a double check I did try from another computer without Kaspersky and it works.
Now the question is how do I fix this for potential users that use kaspersky and wants to use my form?
I am using this Kohana Captcha module in an application. The image renders correctly on my local environment but on our dev environment it returns the following:
�PNG
IHDR 2 1îµM JIDATxÕ|il¤ÉyÞSUßÙýõÅr8$ç¾8«Ñ=¼YÁ¶àݵ9 È°£ÀH #üÌß $#¤ÀFäì$¬X²VÒÚÒjiµëÕÜË!Co²}~gùÑMvl»I$¿`_W}u
¤YZúHPÝ©²Vq×ÝG4øÅ5tªëÕÏN%*v6óB^ï¢kT×A (Å]ïç²m¶Þ^HåsáEÜã\Hµïq5 ni©#)Bé£ûÄ»¥àåsýí5
ª±êgáùØelCóBQý,#¡¤b¦ #QãÚN¶¦o¾pµâEBÚºfk©1ÒlFIÜ qCÀ¥ô¢ªM4µÍFLO¤#Éæo:&ïv¤T~Áoo´C"jè±êÌMánoÌj(*.¥ôqS¿SàB*ð0¥1[×l]3Xsö`:u])¢¥¸heÜFÜHö' !g¹¼Vvs} ÒE§ÛQ~ñ"Ñѵê4M¢ßDxî¤F!?[c¨î^(ä6ÁèEÂ0BlÙºfiLk&í`2f2¤R^ÄC!wZS
¦c¤ Ù<d>xÅ#$ûÍúD¯#¥
J{0Áa3êBñ½:Ô©]ÕYÖÀ»
C®T)à¥Ð)Ý6cbi¥iËJùp£Èço=RÐL]mj¥ËåF é|$z£ìK¤
Êa»kÞ1ÓT ÀýÀ0Xë};a#BBüH§t0tcJHÌÐb Ò¸ s© )ÒjÄ2¶Rª¸TòÛ¹Ê]÷èq½$ûùbXyì(FÁhuwdÈlÇ!#DßRð¢ö$µ©±sSª© ¥ ÓH¨*N*¾KËe(^´Tts!ÄéjrX!éäú\!r[RKû&ªëªZÑn&è®ôØ Ô(áBVuµmRÚ¶snE?,xaUÒÚFs£¶ª8뼸\~ôHå5Ä;cM¾#$}$µþ0ym(§ö ¤vÒ! PñDÌjIº~KÖÝþÈçrv½¢SjÕ.¦ÆvBè˺â4µuÍÖ©±mpjmWZ© w4ALÏ"ÿ± Hj$e}ZAñ±â·I¡¡·«Ý¸lÇ SÂÈvòÆó`jÌÖYÌÐÆiB ÅåâÜù¡4=ÊÍxpø(Ò¯KÉ-'ýÑ(¶a÷Çá56R¼ê, ðê¡?Ú5\£6\R[×Ú#a±;míüPJåfó<h>
g(Çz-3m0*©¢¯,ûù»%wEÔ!TÛm'âv+^kÓ `I#
CxÑM²§qòÖ-cXö&ÖlZ¡Pø~ _(ÀN6A2Jeg
"Ü{û´K9éÌñDj4ÎÌÝiUο·:ÿjpa7©ìnG±Eü¨¡S]#¤v,¥`LµÙûåLJ±Åß6s51G[tKª¤í;N/B±ó+¦±ÎátöA^DMtÝm¦;ô Ç°7CêJªÊ²_YôÜ%_D2ë53'FB`wÇ_x®ëö{P©4ve»*ÚciUɹ3¦ÏLóÃ:ýÝ?|/ôµw{fïv¯Í§mgIoi[Æ6,;ô}!UÀUë¸ì«{XÌ%¢H5Úq4½ö /y}[©N^ø·ãVf{ûo¬\Ëçï¢J³ßóÌñ/I¦ ĺËtrâOg¾5¿'ÁLÆ"/hÍvCÁA}¤DÆMwW ô.ÿ{^E_îê_î
}o:5·²¥±3ç.d^!Ðm5F¬áµ¢|±
Ù[ÂáhÕç÷¿»¸|u]Í'^Yô¾µbuZÉá8 BIçTá~Ù]nQÎÿý+g_¦ëìÓß¡Fä"äJ*îJaKÉÅ]ÉããóGO.LwÌLô±ÈIÂðéùsO:0ºd9~L&¢`2â/x¡ÏÛ°lÙé³W®í8P (£¦cºù`óX-¾üÅrfRï8]ÚùhõzáQc(ä&\ÍféQ !¤{àÌkOÿôkYZ*h¶Ùy¼ô¥óO:Ý)Ý6Eñ×#"Bet øÙWÜß<y>c:'='íö]ö/8©
eÒ¯^)°V ÚJHnRv¦pü³]BQÇj&ëåÚ¦äî6ÛdN8{NC
y÷[óÉxfÔ Çõ_¼ñ¦[¤ÓÜÀËÃrPÏÎrÉý Þ|î_¼:ðÄ(Ð
ë¹láájq!§cr¿v
ÓÄÀhNIÌ~Ú]]]a-~cmdòÆyÊÄÀÈòÈèúÈ°``ty`t
ë+ÎÂl"®-¤ÚèÔr!ÓpåÌç^tFⶣ¯,ÛäÓ¨7ܼßSPäc¿Õ_McIÝþNÔÃcËd÷b JcÅiwð.B#CöâٰتïNÊHd§$Kr(X©øÑgOpsåüûïDAëJôÿü¥®GôêÄ|Û; Hvº#çkñ?i|¦Å\¢²8¸4ytéAW¶(Uf,%ÂÎÅÓW>=ûôL¦·TÌÆÜòÞe ìôÁ ì4¾øÞ¡QiÄ ¢XRKsM¬ ¦S#¦»ëuKFjàN3© ø·¤RT×ÂOÅ{j/ñµÅ§ê¯WrSKÃ×NSßÅáîSG ¬|2·xí»R(>¾¯ÚÑLõá*Æ÷F&¯÷K¾]ÅDAQ_Ú¡D¾<k>¼]¨KÁõ·VB¯jPª>©r #¦wK5¾u°ÍÓª%pAvíN
%¹R
³o¯Õú(ÒÿdmýK멾l}z¥:R\2CÏÏ®}¿?ôõ¦Ï5J¹ø߯øf,¸òÚíu Ró HAÞý3óS±O]ØÓoüÆ;W£ÿùõñ§ºA¬.³¡aÉîÕ·§¤®3:F'óÕ'Áx%Yð¤Õ(~NJrA©ý¤Ä¡Ým'ìâìþ«x2ÃÝÕ¹«Õà~¤k¤vÜS Ô0øaÇklU×ØÕ_|òó÷LP,Q^YÿÁ7ìjñUmCH(ýµÔùËοúÄ#IB(¡|ìTÙBÇpmEB´ÅNv¬N΢î'¬Z. pQu]'kØJdN§3ûÐÎÄT#ä¥Å|} /b¶1ÿÑTq!¯oÏQk,AaäÜòÅÏÍZ{»Ð¼µÄ_þËÈÏMÒ2B ÈÑR6]}ú¾ÜËFÿãk+¿ä$S©ù§·]¥Ðp ¬
ZÑ¿Ý{³F÷±9¯Eë¯s-£ 1ª
Ñl=oÜd×D$γ^
B 1䵯Àtf¤&EsÓ+Ã)B Z ¥!j·è/Ý>½Úøpr"ùÆæQ¥ØäÂ{ HðÌK©'I¼õÝÜĹaYÚSÏg¥#W¢æHæÜø#,¦×GM1RB¬¤¡+A8hOÖüÉ`Ò[×+Õ?bÂý0«4_?VZgUöÛ)E«+¥zm[RÜ
3þÒ':z´
·?ÅÎý¿ÓY.ÿþ*e ض><fw> ¢HÞørçF^)Dàå¨RÒÃNL7^}#ÑŤß'L>âÉZØ1Ô^:ø±>Ó|¾
"^¶®IA5tÑ~§ê\¨Ç¬ÍJ0pyØån½Gó_úʽQF¡öî?½×+Õä>^¸-ÌÝ$´zúbìåW3ï|?ëj?¥$Ó Á¥gjáënÒ¨åÀ¢HDaÕ
'"TÙJjØIÚö&B#©iTËæ²^Êz)moY6ëÊ©DÀe·-¹3tÉ¥Ú½R¯ÉÊM=Ñ ¹XÍVf±f¡8ÜrásO?|ùwnÚA/6dsq=ñ£7*P0BÁ*m1gJ~=ýp:ª9æÛÖ¤;µá1RêÁ-©¤T¾·=Kù2?Sé>éÐôzMÛE\
¢!¡Ë¢)u3ÒAeV~" züôn(ʨÎpA¾6"³î+Å̱îj¢0¿^ͨhA7²wRHîfA¡òÅ/Þyâ(PQsØ>è{ï¯.G Jµ¯:9Ú¤À7þxùòç¿û}ïWRZ_U Â¥§jleþ~TZa¸É|Ûô"÷ö3KFmk¤P³®;ôд
Ø °t*Z{·®!v[O¼ÏP#~Ƶ"ÙfTÙµ2uÖavjE)hA6}%TT9L/¯}õêàñ *,(àÆG'¯}p¶ÚKTK÷aõ¿,iRAüøü{U2þê?è øàÍR ¬ÀR#TÅ/qÔ`F¨É(¦ ¥û0´t ÄFúBlõ:»1bf,FT PtåF©Á!ZÌj;F6 ^Õba5ý'¹äîaâ×}¤ðÛðQ²£¦G(·yDßûáåÉ#m*T
I5½sf
õ²¢GPªÛûÞX;mæ9çó¯g4 Xfîr÷-ÛÜß°$³º![rîÞ|Ä$ÏXdëIÜy*©F®t D¬Ü)¹Ùâf"d d»ªë.,A7ðÄáÊÏÓ~ý]×úùv×2ïû|!GWV
TBî?´îÚ&cUÀä7õ©÷ÿ²_ס J¥(æraoEQ*#q ~hÜù
P.ì>Ãt4¯!r½szÃ/wU#« n}sFDj[#A0Ë ~¸;¦;¡)B*Ùrà ßøö¨_xêó÷ÍNtßùöa a±Búkm½é}».MPLÀh¨uÅÊ祹ðõX|Ào¾ï¯Î7Y`øfCVÓÏGV®ó¨SÐÜ
²ÜìÒ À'c?.V׳dä·MÏé7/ýþPõóä÷VVoh¶Awd+)£4n)¡dÄ¥JV}!B¨ÆzNTSëÖ ¹ä^pµÂ¦½úÕGÎn 0}ôëo\èOiOâj#È?ëÒZOиÃV" yÎ ¥üwKï¿Uzçç_ê¼ô¼õæUv÷7P\Í=ËC :&6Göæ£#æ½êz,ï1ÿW'tX¾^¼ú'3ÕRiÞ¤jî׺"ÌFnxÌtö¾ôÏ>ÊôÔó-ö§ôÞb½Ún´7M£©þ_ÎÖÅÃû~w¯!Cqõý²RBõ£7×zSMïÍ b¦g«åB1 ~)5*#ºsaz¼Vj
©±¸ûó¶³R:¥Þû7SÞ¡34fj»ÝE ÙáN Pjéæ\+vÓñ¥ßúýkUgqÝúÖ\^I°¶s¿Ë;u)ùà?ÿ»¥gíÏ^qRêÚßw^Ê£ÈL(,\jAøÅUàR«OÓlr5SíM>:ó¥¾®Ó %Õíÿ½xãÍÓ°#Û°TRMþøÓc]#Ïg:%J)©2Ǻx$ÜlsùÑ.]yõîç¾p4pýÜTæÏÿø²[2èt{å¶T¨
£^þ½G·p£±,HJ¤:ñìËÉá1óç?+ðv©Rª[½é(RØ_ ÝK÷Å ¤y'wóOsC % µ¥ªµ$ÈutuwïîëÎÏåßýú[-¾¶)é&í«×N^Zn|xíÝ¡ïó¼µuebzoj{ÞäÌÚ~¸¼øk¿÷¯)%£7>q]ιʰg^J8gÿǽØxê(>¿* #çè¶N¿ÞÛq|K0TÙ{¹÷ó3ïäJ«ÈZ3µ^"øô³cg²
NÞü_ç~þöpcÁÛÙQë¼V×Jrcö(ÖuÖØ#Å7ªTëòß*¼ùÿ
JmyÃr¾ Ìö;3«c|»ïDÊNÔðÖ¼¿p3?óaÎ_ßÜÜÃW6%*
¨¦×ØàØzàê÷owûnn6f°£T DÆ'ª¾löÔ[Üpßß.µwgfº¶Ç^éR
ÑtÊRX^Ü¥0ðdà
/÷Øn»")ò¾öÓÄðéìñ+cçW:zÝÏÎ_xv^IÌO§§nöÌÝ9B|gÛ®H©Ü# ¿2ûÂk÷ÞÿþèþïÙvßBJë*h(Ú%µ:üÊ÷¯Ï¬Ü.ñK]u¥« #Æ4E¿«e'±©=S7{ dz*Ç/¬¿¸Ëk¿±Â×»¦3ó÷ÓÒQÀº!3v~ÀOºænJªáQ°átvüÓò]§%7=PSRÖÎåèa·~Ùt1½Qè¬~Î-Ç?\ùð¯G&Fή¿¸rñI%ùè¹ÕÑs«JµEgþ~úÆMSe-Û åyD§?é|¼r¾ëýÕsµßSªýy
ÀDÓQ 무Ä3¦n1 bã¡n5¹øó+Hã©,.&³×7P¬Ø½ë½S7z§ûd78?2ï,v)u)ùÍùRfãâÁÎvK.ªÔ²iãs
¿6Të 8EÈD+Ù;M£U_òºUC?µT£¿ú§²Ü" Ûd 9ûNξóQ¿¦É¾áÂÀh.}n9Ýí9é À½=û[é1R%6ïO©]ÜM¿ÚN" `[µixHr_0R²
ÍúË¢ëùÎñtvóóαeyDç&3·o$þkoWùÄøòñ{×zö·Ò=¸sÅ6¢²¹IçhÛ (3Oò(qÊ a2ÉÆËçáøW®w§³Mñ3¤cË>W
«ÎêóÓïí{è= #ilz£Íjýѽâ®
x #Ó¨®oR#5¤½bô·B ×Ö;)irM_gÄÐèÎE¼Ã9{#(¸Õ ¥DðöÆd"P¤ÉÒ*~ËÚ:ªÓh#o ¸ríÿ¾Ì/ú2VÂb#TQöyõG+l£EryS#íæ"i¡³0ØîÞäê fëlQuN5ä}
˾ÚÏ_ÅFq,ͱ´Þ åBgMtÍa± ZÐó8c¥ PJijó7Ô¾ fn
BP-clìËtë47^©Üû·E04¢mMDè¤l
hb0ÁÔHÿUtéLU IEND®B`
This is the render() method:
public function render($html = TRUE)
{
// Creates $this->image
$this->image_create(Captcha::$config['background']);
// Add a random gradient
if (empty(Captcha::$config['background']))
{
$color1 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
$color2 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
$this->image_gradient($color1, $color2);
}
// Add a few random lines
for ($i = 0, $count = mt_rand(5, Captcha::$config['complexity'] * 4); $i < $count; $i++)
{
$color = imagecolorallocatealpha($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(100, 255), mt_rand(50, 120));
imageline($this->image, mt_rand(0, Captcha::$config['width']), 0, mt_rand(0, Captcha::$config['width']), Captcha::$config['height'], $color);
}
// Calculate character font-size and spacing
$default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / (utf8::strlen($this->response) + 1);
$spacing = (int) (Captcha::$config['width'] * 0.9 / utf8::strlen($this->response));
// Draw each Captcha character with varying attributes
for ($i = 0, $strlen = utf8::strlen($this->response); $i < $strlen; $i++)
{
// Use different fonts if available
$font = Captcha::$config['fontpath'].Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])];
// Allocate random color, size and rotation attributes to text
$color = imagecolorallocate($this->image, mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150));
$angle = mt_rand(-40, 20);
// Scale the character size on image height
$size = $default_size / 10 * mt_rand(8, 12);
$box = imageftbbox($size, $angle, $font, utf8::substr($this->response, $i, 1));
// Calculate character starting coordinates
$x = $spacing / 4 + $i * $spacing;
$y = Captcha::$config['height'] / 2 + ($box[2] - $box[5]) / 4;
// Write text character to image
imagefttext($this->image, $size, $angle, $x, $y, $color, $font, utf8::substr($this->response, $i, 1));
}
// Output
return $this->image_render($html);
}
and the image_render()
/**
* Returns the img html element or outputs the image to the browser.
*
* #param boolean $html Output as HTML
* #return mixed HTML, string or void
*/
public function image_render($html)
{
// Output html element
if ($html === TRUE)
return '<img src="'.url::site('captcha/'.Captcha::$config['group']).'" width="'.Captcha::$config['width'].'" height="'.Captcha::$config['height'].'" alt="Captcha" class="captcha" />';
// Send the correct HTTP header
Request::current()->headers('Content-Type', 'image/'.$this->image_type)
->headers('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0')
->headers('Pragma', 'no-cache')
->headers('Connection', 'close');
// Pick the correct output function
$function = 'image'.$this->image_type;
$function($this->image);
// Free up resources
imagedestroy($this->image);
}
GD library is enabled on the dev environment. Both environments use apache 2.2, php 5.4. Is there another server setting I need to enable?
This type of bugs sometimes bugs me, try to add:
die();
after the last line:
return $this->image_render($html);
Sometimes it works for me.
The text looks like a PNG datastream, only rendered by a text editor instead of an image viewer.
I am using the following code to generate a image using php.
$image_width = 120;
$image_height = 40;
$characters_on_image = 6;
$font = '/fonts/OpenSans.ttf';
//The characters that can be used in the CAPTCHA code.
//avoid confusing characters (l 1 and i for example)
$possible_letters = '23456789bcdfghjkmnpqrstvwxyz';
$random_dots = 10;
$random_lines = 30;
$captcha_text_color="0x142864";
$captcha_noice_color = "0x142864";
$code = '';
$i = 0;
while ($i < $characters_on_image) {
$code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1);
$i++;
}
$font_size = $image_height * 0.75;
$image = #imagecreate($image_width, $image_height);
/* setting the background, text and noise colours here */
$background_color = imagecolorallocate($image, 255, 255, 255);
$arr_text_color = $this->hexrgb($captcha_text_color);
$text_color = imagecolorallocate($image, $arr_text_color['red'],
$arr_text_color['green'], $arr_text_color['blue']);
$arr_noice_color = $this->hexrgb($captcha_noice_color);
$image_noise_color = imagecolorallocate($image, $arr_noice_color['red'],
$arr_noice_color['green'], $arr_noice_color['blue']);
/* generating the dots randomly in background */
for( $i=0; $i<$random_dots; $i++ ) {
imagefilledellipse($image, mt_rand(0,$image_width),
mt_rand(0,$image_height), 2, 3, $image_noise_color);
}
/* generating lines randomly in background of image */
for( $i=0; $i<$random_lines; $i++ ) {
imageline($image, mt_rand(0,$image_width), mt_rand(0,$image_height),
mt_rand(0,$image_width), mt_rand(0,$image_height), $image_noise_color);
}
/* create a text box and add 6 letters code in it */
$textbox = imagettfbbox($font_size, 0, $font, $code);
$x = ($image_width - $textbox[4])/2;
$y = ($image_height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code);
/* Show captcha image in the page html page */
header('Content-Type: image/jpeg');// defining the image type to be shown in browser widow
imagejpeg($image);//showing the image
imagedestroy($image);//destroying the image instance
And i am creating this in a ajax call.
$.ajax({
url : url,
success : function(data){
$("#captcha_text").html(data);
}
});
But when i checked the console no response is getting.How to get this image and display it.Any help is much appreciated.
If you need to create some captcha use the following code,
<img id='captcha' src='your_php_file_path' />
Refresh captcha
<script>
$('#refresh').click(function(){
$('#captcha').attr({
src:'your_php_file_path?hash='+Math.random()*100000,
});
});
</script>
The hash value is passed for avoiding the cached images, the random value will produce a different url , so new images will produced.
Use Data URI, see:
php: recreate and display an image from binary data
You add the AJAX response to the img src attribute, not a ready made image, but de base64 data.
I have a php captcha image script that passes back the captcha code using a session variable, but this won't work if cookies are switched off.
I want to try cover all eventualities, so my form will work even if cookies are switched off.
I was wondering if there was a way to pass $code back from captcha.php to contactus.php without using session variables.
I doubt it, but I thought I'd ask to see if I was missing anything.
captcha.php
session_start();
class CaptchaSecurityImages {
var $font = 'monofont.ttf';
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = #imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 20, 40, 100);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['six_letters_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurityImages($width,$height,$characters);
Contactus.php
<img id="captchaimg" alt="captchaimg" src="<?php echo htmlentities(getSiteURL() . '/server/includes/captcha.php'); ?>"
Your question is more about managing session without having a cookie support, read this article of how to handle session without using cookie
I'm trying to create a captcha code but the code that is being created isn't being stored in the session variable. Here is the file I'm using to create the code and store the value. I have a session_start() on my php page that will display the captcha as well.
<?php session_start();
class CaptchaSecurityImages {
var $font = './monofont.ttf';
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$_SESSION['security_code'] = $code;
$font_size = $height * 0.75;
$image = #imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurityImages($width,$height,$characters);
?>
I can store other items in sessions and they work just fine. I'm not sure why this value won't store. I've found other posts about getting captcha's working but nothing about issues with storing the value in sessions. Any suggestions?
Thanks
Robert
I did end up using reCAPTCHA to accomplish this task.
How is your image being loaded into the user's browser? Is it on the same domain? If it is not, the problem most likely is that your cookie is being excluded because it's a "3rd party cookie." To get the browser to save this cookie, you have to set a P3P header, so the browser knows it's okay to save the cookie.
An example of a valid P3P header would be:
header('P3P: CP="CAO PSA OUR"');
Hope this helps.