各位大侠,小弟刚刚接触PHP,碰到一个验证码的问题, 我直接输入imgcode.inc.php可以正常显示验证码,可是我在另外一个文件中INCLUDE 进去,就显示不了。
验证码文件 imgcode.inc.php<?
session_register("valicode");
$width=50; //先定义图片的长、宽
$height= isset($_REQUEST['height'])?$_REQUEST['height']:18;
$rand_str = "";
for($i=0;$i<4;$i++){
$rand_str .= chr(mt_rand(48,57));
}
if(function_exists("imagecreate")){ $_SESSION["valicode"]=strtolower($rand_str);//注册session
$img = imagecreate($width,$height);//生成图片
imagecolorallocate($img, 255,255,255); //图片底色,ImageColorAllocate第1次定义颜色PHP就认为是底色了
$black = imagecolorallocate($img,127,157,185);
for ($i=1; $i<=50; $i++) { //背景显示雪花的效果
imagestring($img,1,mt_rand(1,$width),mt_rand(1,$height),"#",imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)));
}
for($i=0;$i<4;$i++){ //加入文字
imagestring($img, mt_rand(2,5), $i*10+6, mt_rand(2,5), $rand_str[$i],imagecolorallocate($img,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)));
}
imagerectangle($img,0,0,$width-1,$height-1,$black);//先成一黑色的矩形把图片包围
if(function_exists("imagejpeg")){
header("content-type:image/jpeg\r\n"); imagejpeg($img);
}else{
header("content-type:image/png\r\n"); imagepng($img);
}
imagedestroy($img);
}else{
$_SESSION["valicode"]="1234";
header("content-type:image/jpeg\r\n");
$fp = fopen("./valicode.bmp","r");
echo fread($fp,filesize("./validate.bmp"));
fclose($fp);
}?>plugins index.php<?
include ("../core/config.inc.php");
$q = !isset($_REQUEST['q'])?"":$_REQUEST['q'];
$file = "html/".$q.".inc.php";
if (file_exists($file)){
include_once ($file); exit;
}?>调用方法:plugins/index.php?q=imgcode
验证码文件 imgcode.inc.php<?
session_register("valicode");
$width=50; //先定义图片的长、宽
$height= isset($_REQUEST['height'])?$_REQUEST['height']:18;
$rand_str = "";
for($i=0;$i<4;$i++){
$rand_str .= chr(mt_rand(48,57));
}
if(function_exists("imagecreate")){ $_SESSION["valicode"]=strtolower($rand_str);//注册session
$img = imagecreate($width,$height);//生成图片
imagecolorallocate($img, 255,255,255); //图片底色,ImageColorAllocate第1次定义颜色PHP就认为是底色了
$black = imagecolorallocate($img,127,157,185);
for ($i=1; $i<=50; $i++) { //背景显示雪花的效果
imagestring($img,1,mt_rand(1,$width),mt_rand(1,$height),"#",imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)));
}
for($i=0;$i<4;$i++){ //加入文字
imagestring($img, mt_rand(2,5), $i*10+6, mt_rand(2,5), $rand_str[$i],imagecolorallocate($img,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)));
}
imagerectangle($img,0,0,$width-1,$height-1,$black);//先成一黑色的矩形把图片包围
if(function_exists("imagejpeg")){
header("content-type:image/jpeg\r\n"); imagejpeg($img);
}else{
header("content-type:image/png\r\n"); imagepng($img);
}
imagedestroy($img);
}else{
$_SESSION["valicode"]="1234";
header("content-type:image/jpeg\r\n");
$fp = fopen("./valicode.bmp","r");
echo fread($fp,filesize("./validate.bmp"));
fclose($fp);
}?>plugins index.php<?
include ("../core/config.inc.php");
$q = !isset($_REQUEST['q'])?"":$_REQUEST['q'];
$file = "html/".$q.".inc.php";
if (file_exists($file)){
include_once ($file); exit;
}?>调用方法:plugins/index.php?q=imgcode
解决方案 »
- [正则表达式]请教如何"匹配以某字符串结尾或者结束".例如MV&id=17328895840&scm=102和MV&id=17328895840都可以匹配
- Parse error: syntax error, unexpected 'include' (T_INCLUDE) in D:\myweb\add.php
- 用JQuery AJAX乱码问题 问题虽老还是木解决
- 简单的zend framework问题,求高人指点
- php+access,显示不出结果
- 怎样用php 来 根据DTD的合法性检验 xml !!!!!!!!!!!!!!!!!!!
- 如何把VBB论坛的数据库操作类db_mysql.php改成sql server类
- 如何判断上传的文件是文本文件?
- php语句中变量的问题
- 十进制转化为二进制问题--100分!
- 一个关于$_GET数组的问题
- 求教PHP正则匹配问题
<img src='plugins/index.php?q=imgcode'>他输出的是图片数据流,不能与网页的文本流混在一起