php原生態驗證碼

2021-07-31 07:26:48 字數 890 閱讀 9869

<?php

//開啟session

session_start();

//生成隨機字串

//注:字串的取值可以使用陣列取值方式

function random($len)

return $code;

}//呼叫生成隨機字串

$verification = random(4);

//頭部輸出

header("content-type:image/png");

//定義寬高,方便統一修改

$width = 50;

$height = 25;

//建立資源

$im = imagecreate($width,$height);

//建立顏色

$white = imagecolorallocate($im,255,255,255);

$black = imagecolorallocate($im,0,0,0);

//新增資源的背景顏色

imagefill($im,0,0,$white);

//新增畫素雜點

for($m=0;$m<100;$m++)

//資源新增字串

imagestring($im,5,7,5,$verification,$black);

//資源新增矩形框

imagerectangle($im,0,0,$width-1,$height-1,$black);

//輸出

imagepng($im);

//銷毀資源

imagedestroy($im);

//注入session,方便驗證

$_session['verification']= $verification;

?>

php原生態驗證碼

頭部輸出 header content type image png 建立資源 im imagecreatetruecolor 100,50 建立顏色 black imagecolorallocate im,0,0,0 white imagecolorallocate im,255,255,255 ...

原生php驗證碼

驗證碼 return type description public function actioncode session code md5 verifycode 將字元放入session中 im imagecreate 50,17 生成 black imagecolorallocate im,0...

PHP原生態記錄Log函式

1 因為專案已經上線了,所以除錯起來就不可能把報錯直接輸出來,寫了乙個簡單的日誌函式如下 log要新增的字串 fileprefix 日誌名 filesuffix 日誌字尾 time預設為day function addlog log fileprefix filesuffix log time da...