captcha在localhost中工作正常,但在我的托管中没有

时间:2014-11-25 05:59:15

标签: php joomla

captcha在我的localhost usbwebserwer中运行良好。在web serwer验证码图像中没有显示。当在firefox中打开图像时看到代码:

ÿØÿà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¼Ì…\ó‚pYy­s.£=šÄÚ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通话: 资源解释为图像但使用MIME类型text / html

传输

以下是验证码中的代码:

<?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);
    }
}

这里的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>

1 个答案:

答案 0 :(得分:1)

那是图像。您只是不告诉浏览器它是,您的浏览器将数据解释为文本。设置标题以告知浏览器将数据解释为图像:

header('Content-Type: image/jpeg');

图像数据必须是页面上输出的唯一内容,而不是其他HTML或文本之前或之后。

参考链接:php imagejpeg()

试试这个

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!