參考的網上的,列出一些說明
<?php
session_start();
//生成驗證碼圖片
Header("Content-type: image/PNG");
$im = imagecreate(44,18);
$back = ImageColorAllocate($im, 245,245,245);
imagefill($im,0,0,$back); //背景
srand((double)microtime()*1000000);
//生成4位數字
for($i=0;$i<4;$i++){
$font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255));
$authnum=rand(1,9);
$vcodes.=$authnum;
imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
}
for($i=0;$i<100;$i++) //加入干擾象素
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
$_SESSION['VCODE'] = $vcodes;
?>
Content-type的說明:http://download.csdn.net/source/2024307
Header:
送出 HTTP 協議的標頭到瀏覽器
語法: int header(string string);
返回值: 整數
函數種類: 網絡系統
標頭 (header) 是服務器以 HTTP 協議傳 HTML 資料到瀏覽器前所送出的字符串,在標頭與 HTML 文件之間尚需空一行分隔。在PHP 中送回 HTML 資料前,需先傳完所有的標頭。
注意: 傳統的標頭一定包含下面三種標頭之一,並只能出現一次。
· Content-Type: xxxx/yyyy
· Location: xxxx:yyyy/zzzz
· Status: nnn xxxxxx
在新的多型標頭規格 (Multipart MIME) 方可以出現二次以上。
範例一: 本例用來重導用戶到 PHP 的官方網站。
<?php
Header("Location: http://www.php.net");
exit;
?>
範例二: 欲讓用戶每次都能得到最新的資料,而不是 Proxy 或 cache 中的資料,可以使用下列的標頭
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
範例三: 讓用戶的瀏覽器出現找不到文件的信息。
<?php
header("Status: 404 Not Found");
?>
範例四: [email protected] (28-Apr-1999) 提供讓用戶下載文件的範例。
header("Content-type: application/x-gzip");
header("Content-Disposition: attachment; filename=some-file.tar.gz");
header("Content-Description: PHP3 Generated Data");