图片验证码api

折腾 35 字 472 阅

简言

简单的40以内加法,返回图片,达到简单的验证效果,请自行修改SESSION

注:不会请自行百度$_SESSION

PHP

<?php
session_start();
getValidate(100,25);
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,20);
  $num2 = rand(1,20);
  $_SESSION['code'] = $num1+ $num2;
  imagestring($img, 5, 5, rand(1,10), $num1, $red);
  imagestring($img,5,30,rand(1,10),"+", $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);
} 
?>
- THE END -
打赏 分享
评论 ( 26 )
OωO
  1. Uxsbmm

    tadalafil pills - tadalafil 20 mg tadalafil 20

    13小时前 回复
  2. Txhzao

    buy sildenafil online - silepilled.com natural sildenafil

    昨天 03:18 回复
  3. Uvxsld

    stromectol cost - purchase stromectol ivermectin 1mg

  4. Latvwx

    stromectol how much it cost - stromectol price uk ivermectin for sale online

  5. Uinsyg

    price of doxycycline 100mg - doxycycline cheap uk buy prednisolone 5mg online uk

  6. Ufeqha

    cytotec tablets for sale - cytotec 200 mcg online cytotec singapore

  7. Ofgkbt

    generic ventolin - ventolin price australia buy ventolin inhaler

    9月15日 回复
  8. Pizrap

    cost of furosemide uk - lasix 25 mg furosemide price in india

    9月14日 回复
  9. Bishvz

    prednisone 5mg over the counter - prednisone tablets cost prednisone 12 tablets price

    9月13日 回复
  10. Kgziyi

    ivermectin oral 0 8 - stromectol cost in usa ivermectin nz

    9月12日 回复
  11. Qtejnm

    cialis from australia - Cialis no rx generic cialis over the counter

    9月9日 回复
  12. Dtsctc

    viagra in india cost - Canada meds viagra viagra 30 tablet

    9月8日 回复
  13. Gwtzxc

    paper writing online - essay about the help help writing papers

    9月7日 回复
  14. Mgqscw

    methylprednisolone 16 mg price - lyrica 200 mg cost lyrica cost in india

    9月6日 回复
  15. Tsrlnq

    buy amoxicillin 500 - amoxil online buy amoxicillin 500 mg canada

    9月4日 回复
  16. Adwecs

    accutane online prescription cost - buy accutane australia accutane 5 mg

    9月3日 回复
  17. Adyfbh

    canadian online pharmacy prednisone - generic over the counter prednisone prednisone online no prescription

    9月2日 回复
  18. Sarjdb

    stromectol price uk - buy ivermectin 6mg ivermectin australia

    9月1日 回复
  19. Qtixfs

    vardenafil usa - vardenafil 40mg laura vardenafil generic

    8月30日 回复
  20. Jhnfvm

    tadalafil 5mg daily use - cialis 20 mg price comparison

    8月29日 回复
  21. Deifgk

    viagra 25mg for sale - viagra 50mg over the counter sildenafil New York

    8月27日 回复
  22. Hgsxrg

    medicine neurontin capsules - neurontin 100 synthroid 50 mcg

    8月26日 回复
  23. Ivatah

    doxycycline 200mg price in india - doxycycline 100mg cap tab generic doxycycline 200 mg

    8月25日 回复
  24. Zohmsy

    cytotec price south africa - how to get cytotec over the counter where to buy cytotec in us

    8月23日 回复
  25. Qupram

    ventolin australia price - ventolin 90 mcg cost of ventolin in usa

    8月22日 回复
  26. Mdsbaw

    ivermectin cream canada cost - ivermectin 6mg ivermectin tablets order

    8月20日 回复
感谢打赏