php數字運算驗證碼的實現代碼_php執行個體

來源:互聯網
上載者:User

本文執行個體講述了php實現數字運算驗證碼的方法,具體實現方法如下:

<?phpgetValidate(100,30); function getValidate($w,$h){ $img = imagecreate($w,$h);  $gray = imagecolorallocate($img,255,255,255); $black = imagecolorallocate($img,rand(0,200),rand(0,200),rand(0,200)); $red = imagecolorallocate($img, 255, 0, 0); $white = imagecolorallocate($img, 255, 255, 255); $green = imagecolorallocate($img, 0, 255, 0); $blue = imagecolorallocate($img, 0, 0, 255); imagefilledrectangle($img, 0, 0, 100, 30, $black);   for($i = 0;$i < 80;$i++){  imagesetpixel($img, rand(0,$w), rand(0,$h), $gray); }   $num1 = rand(1,99); $num2 = rand(1,99);  imagestring($img, 5, 5, rand(1,10), $num1, $red); imagestring($img,5,30,rand(1,10),getRand(), $white); imagestring($img,5,45,rand(1,10),$num2, $green); imagestring($img,5,65,rand(1,10),"=", $blue); imagestring($img,5,80,rand(1,10),"?", $red);    header("content-type:image/png"); imagepng($img); imagedestroy($img);}function getRand(){ $code = rand(0,1); switch ($code) {  case 0:   return "+";   break;  case 1:   return "-";   break;  default:   # code...   break; }} ?>

實現效果:

以上介紹的就是使用php實現數字運算驗證碼的方法,希望對大家的學習有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.