課程
/后端開發
/PHP
/手把手教你實現電商網站后臺開發
按照老師的步驟還是顯示不了驗證碼!還有老師哪些login、main、index、的PHP都是要自己打上?那些能用靜態網站編輯嗎?
2016-02-18
源自:手把手教你實現電商網站后臺開發 2-1
正在回答
字體加載的問題!我這樣寫的時候,很多時候會加載不了驗證碼,有時可以顯示
$fontfiles = array(
? ? ? ? "SIMYOU.TTF",
? ? ? ? "MSYHL.TTC",
? ? ? ? "MSYH.TTC"
? );
后來我這樣寫就不會出現一時有,一時沒有的情況
? ? );
一進酒吧就變壞l 提問者
我的解決方法是:
這樣就可以顯示了,因為是新手,感覺應該是路徑問題
和我一樣的問題,換了360瀏覽器,谷歌瀏覽器,火狐都是這樣
我這邊是顯示這樣的。不知道什么問題。麻煩老師幫忙解決一下?。。≈x謝
<?php//通過GD庫做驗證碼//引用字符串類 得到隨機字符串require_once 'string.func.php';function verifyimage($type, $length, $line, $pixel, $width, $height) {?? ??? ?$chars = buildRandomString ( $type, $length );?? ?$_SESSION ["verify1"] = $chars;?? ??? ?//驗證碼圖片的寬高?? ?//創建畫布?? ?$image = imagecreatetruecolor ( $width, $height );?? ?$white = imagecolorallocate ( $image, 255, 255, 255 );?? ?//填充矩形畫布?? ?imagefilledrectangle ( $image, 1, 1, $width - 2, $height - 2, $white );?? ??? ?//輸出字符 每個字的顏色不一樣怎么辦??? ?//由于字體的原因找成有的時候沒有數字,請注意?? ?$fontfiles = array ("batang.ttc", "calibri.ttf" );?? ?for($j = 0; $j < $length; $j ++) {?? ??? ?$size = mt_rand ( 14, 18 );?? ??? ?$angle = mt_rand ( - 15, 15 );?? ??? ?$x = 5 + $j * $size;?? ??? ?$y = mt_rand ( 20, 26 );?? ??? ?$color = imagecolorallocate ( $image, mt_rand ( 50, 90 ), mt_rand ( 80, 200 ), mt_rand ( 90, 180 ) );?? ??? ?$fontfile = "../font/" . $fontfiles [mt_rand ( 0, count ( $fontfiles ) - 1 )];?? ??? ??? ??? ?$text = substr ( $chars, $j, 1 );?? ??? ?imagettftext ( $image, $size, $angle, $x, $y, $color, $fontfile, $text );?? ?}?? ?//加干擾點?? ??? ?if ($pixel) {?? ??? ?$color = imagecolorallocate ( $image, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );?? ??? ?for($i = 0; $i < $pixel; $i ++) {?? ??? ??? ?imagesetpixel ( $image, mt_rand ( 0, $width ), mt_rand ( 0, $height ), $color );?? ??? ?}?? ?}?? ?//加干擾線?? ??? ?if ($line) {?? ??? ?for($i = 0; $i < $line; $i ++) {?? ??? ??? ?$color = imagecolorallocate ( $image, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );?? ??? ??? ?imageline ( $image, mt_rand ( 0, $width ), mt_rand ( 0, $height ), mt_rand ( 0, $width ), mt_rand ( 0, $height ), $color );?? ??? ?}?? ?}?? ?//聲明輸出圖片的格式?? ? @header ( "Content-Type:image/png" );?? ?//輸出圖片?? ?imagepng ( $image );?? ?//銷毀圖片資源?? ?imagedestroy ( $image );}
php文件都是編輯工具自動生成的
舉報
手把手教你用PHP搭建電子商務平臺,由淺入深教你搭建電商系統
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-04-04
字體加載的問題!我這樣寫的時候,很多時候會加載不了驗證碼,有時可以顯示
$fontfiles = array(
? ? ? ? "SIMYOU.TTF",
? ? ? ? "MSYHL.TTC",
? ? ? ? "MSYH.TTC"
? );
后來我這樣寫就不會出現一時有,一時沒有的情況
$fontfiles = array(
? ? ? ? "MSYH.TTC"
? ? );
2016-03-01
我的解決方法是:
這樣就可以顯示了,因為是新手,感覺應該是路徑問題
2016-02-23
和我一樣的問題,換了360瀏覽器,谷歌瀏覽器,火狐都是這樣
2016-02-19
2016-02-18
<?php
//通過GD庫做驗證碼
//引用字符串類 得到隨機字符串
require_once 'string.func.php';
function verifyimage($type, $length, $line, $pixel, $width, $height) {
?? ?
?? ?$chars = buildRandomString ( $type, $length );
?? ?$_SESSION ["verify1"] = $chars;
?? ?
?? ?//驗證碼圖片的寬高
?? ?//創建畫布
?? ?$image = imagecreatetruecolor ( $width, $height );
?? ?$white = imagecolorallocate ( $image, 255, 255, 255 );
?? ?//填充矩形畫布
?? ?imagefilledrectangle ( $image, 1, 1, $width - 2, $height - 2, $white );
?? ?
?? ?//輸出字符 每個字的顏色不一樣怎么辦?
?? ?//由于字體的原因找成有的時候沒有數字,請注意
?? ?$fontfiles = array ("batang.ttc", "calibri.ttf" );
?? ?for($j = 0; $j < $length; $j ++) {
?? ??? ?$size = mt_rand ( 14, 18 );
?? ??? ?$angle = mt_rand ( - 15, 15 );
?? ??? ?$x = 5 + $j * $size;
?? ??? ?$y = mt_rand ( 20, 26 );
?? ??? ?$color = imagecolorallocate ( $image, mt_rand ( 50, 90 ), mt_rand ( 80, 200 ), mt_rand ( 90, 180 ) );
?? ??? ?$fontfile = "../font/" . $fontfiles [mt_rand ( 0, count ( $fontfiles ) - 1 )];
?? ??? ?
?? ??? ?$text = substr ( $chars, $j, 1 );
?? ??? ?imagettftext ( $image, $size, $angle, $x, $y, $color, $fontfile, $text );
?? ?}
?? ?//加干擾點
?? ?
?? ?if ($pixel) {
?? ??? ?$color = imagecolorallocate ( $image, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );
?? ??? ?for($i = 0; $i < $pixel; $i ++) {
?? ??? ??? ?imagesetpixel ( $image, mt_rand ( 0, $width ), mt_rand ( 0, $height ), $color );
?? ??? ?}
?? ?}
?? ?//加干擾線
?? ?
?? ?if ($line) {
?? ??? ?for($i = 0; $i < $line; $i ++) {
?? ??? ??? ?$color = imagecolorallocate ( $image, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );
?? ??? ??? ?imageline ( $image, mt_rand ( 0, $width ), mt_rand ( 0, $height ), mt_rand ( 0, $width ), mt_rand ( 0, $height ), $color );
?? ??? ?}
?? ?}
?? ?//聲明輸出圖片的格式
?? ? @header ( "Content-Type:image/png" );
?? ?//輸出圖片
?? ?imagepng ( $image );
?? ?//銷毀圖片資源
?? ?imagedestroy ( $image );
}
php文件都是編輯工具自動生成的
2016-02-18
<?php
//通過GD庫做驗證碼
//引用字符串類 得到隨機字符串
require_once 'string.func.php';
function verifyimage($type, $length, $line, $pixel, $width, $height) {
?? ?
?? ?$chars = buildRandomString ( $type, $length );
?? ?$_SESSION ["verify1"] = $chars;
?? ?
?? ?//驗證碼圖片的寬高
?? ?//創建畫布
?? ?$image = imagecreatetruecolor ( $width, $height );
?? ?$white = imagecolorallocate ( $image, 255, 255, 255 );
?? ?//填充矩形畫布
?? ?imagefilledrectangle ( $image, 1, 1, $width - 2, $height - 2, $white );
?? ?
?? ?//輸出字符 每個字的顏色不一樣怎么辦?
?? ?//由于字體的原因找成有的時候沒有數字,請注意
?? ?$fontfiles = array ("batang.ttc", "calibri.ttf" );
?? ?for($j = 0; $j < $length; $j ++) {
?? ??? ?$size = mt_rand ( 14, 18 );
?? ??? ?$angle = mt_rand ( - 15, 15 );
?? ??? ?$x = 5 + $j * $size;
?? ??? ?$y = mt_rand ( 20, 26 );
?? ??? ?$color = imagecolorallocate ( $image, mt_rand ( 50, 90 ), mt_rand ( 80, 200 ), mt_rand ( 90, 180 ) );
?? ??? ?$fontfile = "../font/" . $fontfiles [mt_rand ( 0, count ( $fontfiles ) - 1 )];
?? ??? ?
?? ??? ?$text = substr ( $chars, $j, 1 );
?? ??? ?imagettftext ( $image, $size, $angle, $x, $y, $color, $fontfile, $text );
?? ?}
?? ?//加干擾點
?? ?
?? ?if ($pixel) {
?? ??? ?$color = imagecolorallocate ( $image, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );
?? ??? ?for($i = 0; $i < $pixel; $i ++) {
?? ??? ??? ?imagesetpixel ( $image, mt_rand ( 0, $width ), mt_rand ( 0, $height ), $color );
?? ??? ?}
?? ?}
?? ?//加干擾線
?? ?
?? ?if ($line) {
?? ??? ?for($i = 0; $i < $line; $i ++) {
?? ??? ??? ?$color = imagecolorallocate ( $image, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );
?? ??? ??? ?imageline ( $image, mt_rand ( 0, $width ), mt_rand ( 0, $height ), mt_rand ( 0, $width ), mt_rand ( 0, $height ), $color );
?? ??? ?}
?? ?}
?? ?//聲明輸出圖片的格式
?? ? @header ( "Content-Type:image/png" );
?? ?//輸出圖片
?? ?imagepng ( $image );
?? ?//銷毀圖片資源
?? ?imagedestroy ( $image );
}
php文件都是編輯工具自動生成的