当前位置:Gxlcms > PHP教程 > php绘图有关问题求教

php绘图有关问题求教

时间:2021-07-01 10:21:17 帮助过:24人阅读

php 绘图 问题求教?
问题如下:
1 attention.php
if(!defined('INC_CHECK'))
{
die("error!");
}
2 globals.php
require 'attention.php';//删除这句话,验证码图片正常,否则无效
function code()
{
//验证码绘图程序见备注
}
3 code.php
define('INC_CHECK',1);
require 'globals.php';
code();
备注:
$_mt_randcode="";
$width=75;
$height=25;
for($i=0;$i<4;$i++)
{
$_mt_randcode.=dechex(mt_rand(0, 15));
}
session_start();
$_SESSION['checkcode']=$_mt_randcode;
$im=imagecreatetruecolor($width, $height);
header("Content-Type:image/png");
$white=imagecolorallocate($im,255,255,255);
$black=imagecolorallocate($im, 0, 0, 0);
imagefill($im, 0, 0, $white);
imagerectangle($im, 1, 1, $width-1, $height-1, $black);
for($i=0;$i<6;$i++)
{
$_rnd_color=imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imageline($im, mt_rand(0, 75), mt_rand(0, 75), mt_rand(0, 75), mt_rand(0, 75), $_rnd_color);
}
for($i=0;$i<15;$i++)
{
imagestring($im, 1, mt_rand(0, $width),mt_rand(0, $height), '*',imagecolorallocate($im, mt_rand(100, 200), mt_rand(100, 150), mt_rand(100, 200)) );
}
for($i=0;$i {
imagestring($im, mt_rand(3, 5), $i*$width/4+mt_rand(0,10), mt_rand(1,$height/2), $_SESSION['checkcode'][$i], imagecolorallocate($im, mt_rand(0, 255), mt_rand (0, 150), mt_rand(0, 200)));
}
imagepng($im);
imagedestroy($im); php image session


------解决方案--------------------
attention.php 文件有BOM头?

人气教程排行