作者jackyeah1213 (frog)
看板PHP
标题Re: [请益] 验证码图案跑不出来
时间Mon Aug 27 13:25:46 2012
根据建议
将php做了相关的修改
<?php
session_start();
create_image();
exit();
function create_image(){
$security_code =$_SESSION["security_code"];
$image = @imagecreatefromjpeg("images/static.jpg");
$black = imagecolorallocate($image, 0, 0, 0);
$vPos = 4;
$hPos = 30;
$fontSize = 5;
imagestring($image, $fontSize, $hPos, $vPos, $security_code, $black);
header("Content-Type: image/jpeg");
imagejpeg($image);
imagedestroy($image);
}
背景图片有成功的显示出来
但是验证码文字还是无法正确的显示...
请问是怎麽回事呢~"~
※ 引述《shadowjohn (D3 私服架好喽!!!)》之铭言:
: ※ 引述《jackyeah1213 (frog)》之铭言:
: : html:
: : <img src="captcha.php" id="captcha" alt="captcha" />
: : php:
: : <?session_start();?>
: : <?php
: : create_image();
: : exit();
: : function create_image(){
: : $security_code =$_SESSION["security_code"];
: : $image = @imagecreatefromjpeg("images\static.jpg");
: : $black = ImageColorAllocate($image, 0, 0, 0);
: : $vPos = 4;
: : $hPos = 30;
: : $fontSize = 5;
: : ImageString($image, $fontSize, $hPos, $vPos, $security_code, $black);
: : header("Content-Type: image/jpeg");
: : ImageJpeg($image);
: : ImageDestroy($image);
: : }
: : ?>
: 第一:
: <?session_start();?> 和 <?php 之间有断行,明显有 bom 的问题,请合并修改成
: <?php
: session_start();
: create_image();
: 第二:
: 最後一行,後面不可以有输出,所以最好 ?> 乾脆不要打了
: 第三:
: $image = @imagecreatefromjpeg("images\static.jpg");
: 请改成
: $image = @imagecreatefromjpeg("images\\static.jpg");
: 或(推荐)
: $image = @imagecreatefromjpeg("images/static.jpg");
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.163.194.235
1F:推 kerash:不要用@直接连结该图片页看看会有甚麽讯息 08/27 13:55
没有跳出什麽讯息欸@@
2F:推 TeemingVoid:有哪一段程式设定$_SESSION["security_code"]的值呢:) 08/27 14:12
$md5_hash = md5(rand(0,9999999999999999));
$md5_hash = hexdec($md5_hash);
$security_code = substr($md5_hash, 5, 4);
$_SESSION["security_code"] = $security_code;
$_SESSION["security_code"] 是基本页面所产生的
而captcha.php 则是单纯把session叫出来
去产生文字
※ 编辑: jackyeah1213 来自: 118.163.194.235 (08/27 14:52)
3F:→ TeemingVoid:你的程式如果改成 $security_code = '123'; 就会有背 08/27 15:49
4F:→ TeemingVoid:也有123字样,所以,原程式肯定还没有程式设定 session 08/27 15:51
5F:→ arrack:楼上+1 08/27 16:54
最後真的发现是session问题 T^T
我还一直陷入验证码生成错误的回圈当中...
太感谢各位的帮助了....m(_ _)m
※ 编辑: jackyeah1213 来自: 36.232.248.55 (08/27 21:23)