嗨,我在Google Chrome浏览器的GET部分有问题。您可以通过此 DEMO
更好地了解请使用Google Chrome和Internet Explorer或Firefox打开演示页面。它可以正常运行Internet Explorer,Firefox或其他浏览器,但不能仅在chrome上运行。
任何人都可以在这里帮助我。
code.php文件代码在这里:
<?php if ( !isset( $_SESSION ) ) session_start(); header( "(anti-spam-content-type:) image/png" );
$acf_num = rand( 0, 9999 );
$code_num = rand( 0, 24 );
$mixed_string = substr( md5( $acf_num ), $code_num, 5 ); // Length of String
$mixed_md5 = md5( $mixed_string );
$_SESSION['SocialMaterial']['AnimationContactForm']['verifyCode'] = $mixed_md5;
// Verification Image Background randomizer
$rand = dirname( dirname( __FILE__ ) ) . '/';
$CoDes = array(
$rand . 'acf_img/verify/1.png',
$rand . 'acf_img/verify/2.png',
$rand . 'acf_img/verify/3.png'
);
$VerifyCodes = array_rand( $CoDes, 1 );
// Verification Image Configurations
$img_handle = imagecreatefrompng( $CoDes[$VerifyCodes] );
$text_colour = imagecolorallocate( $img_handle, 255, 255, 255 );
$font_size = 50;
$size_array = getimagesize( $CoDes[$VerifyCodes] );
$img_w = $size_array[0];
$img_h = $size_array[1];
$horiz = round( ( $img_w/2 )-( ( strlen( $mixed_string )*imagefontwidth( 50 ) )/2 ), 1 );
$vert = round( ( $img_h/2 )-( imagefontheight( $font_size )/2 ) );
// Make the Verification Image
imagestring( $img_handle, $font_size, $horiz, $vert, $mixed_string, $text_colour );
imagepng( $img_handle );
// Destroy the Image to keep Server Space
imagedestroy( $img_handle );
问题开发者控制台是这样的:
答案 0 :(得分:1)
我无法验证这是否可以解决您的问题,但是您需要通过HTML标头告诉浏览器它是哪种图像类型:
header('Content-type: image/png');
header('Content-transfer-encoding: binary');
header('Content-length: '.$size);
这是用于$size
大小的PNG文件。标头应先发送到浏览器。
答案 1 :(得分:1)
只需更改您的 code.php 代码,如下所示:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
if ( !isset( $_SESSION ) ) session_start();
header('Content-type: image/png');
header('Content-transfer-encoding: binary');
$acf_num = rand( 0, 9999 );
$code_num = rand( 0, 24 );
$mixed_string = substr( md5( $acf_num ), $code_num, 5 ); // Length of String
$mixed_md5 = md5( $mixed_string );
header("Content-Disposition: inline; fileimg= $acf_num-$code_num");
$_SESSION['SocialMaterial']['AnimationContactForm']['verifyCode'] = $mixed_md5;
// Verification Image Background randomizer
$rand = dirname( dirname( __FILE__ ) ) . '/';
$CoDes = array(
$rand . 'acf_img/verify/1.png',
$rand . 'acf_img/verify/2.png',
$rand . 'acf_img/verify/3.png'
);
$VerifyCodes = array_rand( $CoDes, 1 );
// Verification Image Configurations
$img_handle = imagecreatefrompng( $CoDes[$VerifyCodes] );
$text_colour = imagecolorallocate( $img_handle, 255, 255, 255 );
$font_size = 50;
$size_array = getimagesize( $CoDes[$VerifyCodes] );
$img_w = $size_array[0];
$img_h = $size_array[1];
$horiz = round( ( $img_w/2 )-( ( strlen( $mixed_string )*imagefontwidth( 50 ) )/2 ), 1 );
$vert = round( ( $img_h/2 )-( imagefontheight( $font_size )/2 ) );
// Make the Verification Image
imagestring( $img_handle, $font_size, $horiz, $vert, $mixed_string, $text_colour );
imagepng( $img_handle );
// Destroy the Image to keep Server Space
imagedestroy( $img_handle );
更改日志:
已删除:header( "(anti-spam-content-type:) image/png" );
添加了标头,因为您应该通过HTML标头告诉浏览器它是哪种图像类型:
header('Content-type: image/png');
header('Content-transfer-encoding: binary');
header("Content-Disposition: inline; fileimg= $acf_num-$code_num");