| Server IP : 210.245.233.93 / Your IP : 216.73.216.226 Web Server : Apache/2.2.15 (CentOS) System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : apache ( 48) PHP Version : 5.3.3 Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hkosl.com/m.musiccircle/ |
Upload File : |
<?php
header("Content-type:image/png");
#header("Content-Disposition:filename=image_code.png");
//定義 header 的文件格式為 png,第二個定義其實沒什麼用
// 開啟 session
if (!isset($_SESSION)) { session_start(); }
// 設定亂數種子
mt_srand((double)microtime()*1000000);
// 驗證碼變數
$verification__session = '';
// 定義顯示在圖片上的文字,可以再加上大寫字母
$str = 'abcdefghijkmnpqrstuvwxyz23456789';
$l = strlen($str); //取得字串長度
//隨機取出 6 個字
for($i=0; $i<6; $i++){
$num=rand(0,$l-1);
$verification__session.= $str[$num];
}
// 將驗證碼記錄在 session 中
$_SESSION["verification__session"] = $verification__session;
// 圖片的寬度與高度
$imageWidth = 160; $imageHeight = 50;
// 建立圖片物件
$im = @imagecreatetruecolor($imageWidth, $imageHeight)
or die("無法建立圖片!");
//主要色彩設定
// 圖片底色
$bgColor = imagecolorallocate($im, 255,255,255);
// 文字顏色
$Color = imagecolorallocate($im, 200,132,43);
// 干擾線條顏色
$gray1 = imagecolorallocate($im, 200,200,200);
// 干擾像素顏色
$gray2 = imagecolorallocate($im, 200,200,200);
//設定圖片底色
imagefill($im,0,0,$bgColor);
//底色干擾線條
/*for($i=0; $i<10; $i++){
imageline($im,rand(0,$imageWidth),rand(0,$imageHeight),
rand($imageHeight,$imageWidth),rand(0,$imageHeight),$gray1);
} */
//利用true type字型來產生圖片
imagettftext($im, 25, 5, 10, 40, $Color,
"fonts/AdobeGothicStd-Bold.otf",
$verification__session);
/*
imagettftext (int im, int size, int angle,
int x, int y, int col,
string fontfile, string text)
im 圖片物件
size 文字大小
angle 0度將會由左到右讀取文字,而更高的值表示逆時鐘旋轉
x y 文字起始座標
col 顏色物件
fontfile 字形路徑,為主機實體目錄的絕對路徑,
可自行設定想要的字型
text 寫入的文字字串
*/
// 干擾像素
for($i=0;$i<90;$i++){
imagesetpixel($im, rand()%$imageWidth ,
rand()%$imageHeight , $gray2);
}
imagepng($im);
imagedestroy($im);