復制代碼 代碼如下:
<?php
/**
* 仿QQ驗證碼
*/
//Session保存路徑
$sessSavePath = dirname(__FILE__)
if(is_writeable($sessSavePath) && is_readable($sessSavePath)){ session_save_path($sessSavePath); }
session_start();
//獲取隨機字符
$rndstring =
for($i=
$img_height=
$img_width=
//如果支持GD
if(function_exists("imagecreate"))
{
//Firefox部份情況會多次請求的問題
$ntime = time();
if(empty($_SESSION[
{
$_SESSION[
$_SESSION[
}
$rndstring = $_SESSION[
$rndcodelen = strlen($rndstring);
//創建圖片
$im = imagecreate(
ImageColorAllocate($im
//干擾線
$lineColor
for($j=
{
imageline($im
}
//輸出文字
$fontColor = ImageColorAllocate($im
for($i=
{
$bc = mt_rand(
$rndstring[$i] = strtoupper($rndstring[$i]);
imagestring($im
}
header("Pragma:no
header("Cache
header("Expires:
//輸出特定類型的圖片格式
if(function_exists("imagepng"))
{
header("content
imagepng($im);
}
else
{
header("content
imagejpeg($im);
}
ImageDestroy($im);
exit();
}
else
{
//不支持GD
$_SESSION[
$_SESSION[
header("content
header("Pragma:no
header("Cache
header("Expires:
$fp = fopen("data/vdcode
echo fread($fp
fclose($fp);
exit();
}
?>
From:http://tw.wingwit.com/Article/program/PHP/201311/21002.html