出現亂碼是因為header出現了問題,注意千萬不要有空格,可以復制粘貼下面這一行,希望可以幫到大家:
header('content-type:image/png');
header('content-type:image/png');
2017-11-18
舉一反三, 那是最好的, 這里實現了簡單的數字驗證碼,數字文字混合驗證碼, 中文驗證碼, 圖片驗證碼, 其他驗證碼基本邏輯應該會有完全相同或者相似的地方, 老師的這種面對問題的處理邏輯,是值得學習的
2017-11-04
不管是數字驗證碼,還是圖片驗證碼 只要是要我們輸入的,肯定要在驗證碼生成的那個地方, 保存一個確定的值到SESSION中
用下面的方法好像更合理,
$arr = array(
'image0'=>'寬帶',
'image1'=>'美女'
);
$rand = array_rand($arr,1);
$image = "./image/". $rand . '.png';
$image = imagecreatefrompng($image);
if ($image) {
$_SESSION['auth_image'] = $arr[$rand];
}
// ..識別輸出
用下面的方法好像更合理,
$arr = array(
'image0'=>'寬帶',
'image1'=>'美女'
);
$rand = array_rand($arr,1);
$image = "./image/". $rand . '.png';
$image = imagecreatefrompng($image);
if ($image) {
$_SESSION['auth_image'] = $arr[$rand];
}
// ..識別輸出
2017-11-04
取一個字符串中的 一個隨機字符用下面這種方法是不是更好?
$str = 'abcedfghijklmnopqrstuvwxyz0123456789';
$cha = $str{rand(0,strlen($str))};
echo $cha;
$str = 'abcedfghijklmnopqrstuvwxyz0123456789';
$cha = $str{rand(0,strlen($str))};
echo $cha;
2017-11-04
通過array_rand函數生成一個字母數字貌似要定義好多數組值。。。
$arr = array('數字','字母');
$defaultKey = array_rand($arr,1)
$cha = $arr[$defaultKey]; //我是隨機數對應鍵名的數組值
$arr = array('數字','字母');
$defaultKey = array_rand($arr,1)
$cha = $arr[$defaultKey]; //我是隨機數對應鍵名的數組值
2017-11-04
漢字驗證碼一直顯示不出來,錯誤如下:
Warning: imagettftext(): Could not find/open font in D:\study\others\PHP\php實現驗證碼\verificationCode\captcha_cn.php on line 65
PHP Warning: Cannot modify header information - headers already sent by (output started at
Warning: imagettftext(): Could not find/open font in D:\study\others\PHP\php實現驗證碼\verificationCode\captcha_cn.php on line 65
PHP Warning: Cannot modify header information - headers already sent by (output started at
2017-10-16