我在输入中获得了验证码加密值,例如:
value=" JFIF >CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality
C $.' ",#(7),01444'9=82<.342 C2!!22222222222222222222222222222222222222222222222222 ( x"
} !1AQa "q2 #B R $3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
w !1AQ aq"2 B #3R br
$4 % &'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz ? Ԓ 61N 7I v n % O;pHU C8Xn " + 8 s c NNGw e ֱx4裴 Ԡ;+ uv i Q ea @@ [ o H. D!K7 6 ) CR nq t3m O R g$ L Ź `:ǘ s6 n| U PC h M 7y F W X R RX8u c 'c )] kw$ p _ w > 5 ˩P ̪ 4h? .7n Th +mbn' , ][Ķ| I$pe "
如何获得像"CDEF01jhdfz"这样的普通加密字符串而不是上面的字符串?我认为这是一个加密问题。这是我的代码:
function str_encrypt( $str ) {
$mystr = index_array( $str, KEY_VALUES );
$mystr = mybase64_encode( rawurlencode( $mystr ) );
return $mystr;
}
function str_decrypt( $str ) {
$mystr = rawurldecode( mybase64_decode( $str ) ) ;
$mystr = index_array( $mystr, KEY_VALUES );
return $mystr;
}
$captcha = new CaptchaCode();
$code = str_encrypt( $captcha->generateCode(6) );
$captcha1 = new CaptchaImages();
$captcha1->GenerateImage( $width, $height, str_decrypt( $code ) );
echo $code;
i m getting $code value through below function on my index.php:
jQuery.get('<?php echo captcha_images.php ?>', function( encoded_code ) {
jQuery('#security_check').val( encoded_code );
}
你不需要复杂的代码,我通常通过会话传递代码。
image_captcha.php创建如下代码:19m92d9193jf9。你可以使用 md5() 来生成它,并使用 substr() 来缩短它。
使用此代码显示图像,然后在会话变量中设置此值。
所以当前的 php 文件无需更多努力即可获得此值。只需访问图像即可。
image_captcha.php
$basepath = DIR_VIEWS.'/captcha/';
$code = substr(md5(time()),0,7);
$_SESSION['code_captcha'] = $code;
$imageCaptcha = imagecreatefrompng($basepath."background.png");
$fontCaptcha = imageloadfont($basepath."anonymous.gdf");
$color = imagecolorallocate($imageCaptcha,rand(1,255),0,0);
imagestring($imageCaptcha,$fontCaptcha,15,rand(3,10),$codigoCaptcha{0},$color);
imagestring($imageCaptcha,$fontCaptcha,35,rand(3,10),$codigoCaptcha{1},$color);
imagestring($imageCaptcha,$fontCaptcha,55,rand(3,10),$codigoCaptcha{2},$color);
imagestring($imageCaptcha,$fontCaptcha,75,rand(3,10),$codigoCaptcha{3},$color);
imagestring($imageCaptcha,$fontCaptcha,125,rand(3,10),$codigoCaptcha{4},$color);
imagestring($imageCaptcha,$fontCaptcha,145,rand(3,10),$codigoCaptcha{5},$color);
imagestring($imageCaptcha,$fontCaptcha,165,rand(3,10),$codigoCaptcha{6},$color);
header("Content-type: image/png");
imagepng($imageCaptcha);
imagedestroy($imageCaptcha);
exit();
访问此文件:
<img src="image_captcha.php"/>
在这里,验证码已准备好进行检查。
如果我理解你的代码和注释,你有一个名为captcha_images.php
的未公开脚本,它生成并发送原始的JPEG图片。然后,您可以使用客户端 JavaScript 将其放入 HTWML 属性中。
jQuery.val()
方法需要纯文本:
.val( 值 )
value Type: String or Array
与要设置为选中/选中的每个匹配元素的值相对应的文本字符串或字符串数组。
。这是完全有意义的,因为HTML本身根本不是二进制格式:
Content-Type: text/html
^^^^
这意味着之后无法取回原始二进制数据。将其转换为文本的过程将破坏它。
我不知道"普通加密字符串"是什么意思,但您可能应该从服务器发送它以备使用。