但不能在我的主机上运行

但不能在我的主机上运行

本文介绍了验证码可以在本地主机上正常运行,但不能在我的主机上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

验证码在我的本地主机usbwebserwer中运行良好.在网络服务器验证码图像中未显示.在firefox中打开图像时,请参见代码:

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¼Ì…\ó‚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‡FyóÕÁ!ˆ¢³Ý¤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

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

此处是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');

图像数据将必须是页面上唯一的输出,之前或之后必须没有其他HTML或文本.

The image data will have to be the only thing output on the page, no other HTML or text before or after it.

引用链接: 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!

这篇关于验证码可以在本地主机上正常运行,但不能在我的主机上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 06:12