検証コード PHP クラスは数字、文字、漢字、混合をサポートします

WBOY
リリース: 2016-07-25 08:46:21
オリジナル
789 人が閲覧しました
  1. // +-------------------------------------- -- ----------------------------------
  2. // 検証コードクラス、このクラスのオブジェクトは動的に取得可能認証コード 写真と認証コードの文字は SESSION['code'] に保存されます
  3. // +---------------------------- -- --------------------------------------
  4. //4 つの形式の数値をサポート、文字と漢字のミックス
  5. // +----------------------------------------------------- -------- ------------------------
  6. // @著者: HelloChina(sanzi0930@163.com)
  7. / / +----- -------------------------------------- ------- ------------------
  8. // @日付: 2012 年 6 月 7 日 11:03:00
  9. // +------ ---------------------------------------------------- -------- ----------
  10. // @バージョン 1.0
  11. // +---------------------- ---------------------------------------------------- -
  12. class Vcode{
  13. protected $ width; // 検証コードの長さ
  14. protected $codeNum; // 検証コードの文字数
  15. protected $codeType; // 検証コードの種類
  16. ; $fontSize; //文字サイズ
  17. protected $fontType; //フォントタイプ
  18. protected $strNum; //出力画像タイプ
  19. / /画像リソース
  20. protected $checkCode; //検証コードの内容
  21. /**
  22. +------------------------------------------------ --------------------------------
  23. * 認証コード情報を取得する
  24. +---------- -------------------------------------------------- --------------------
  25. * @param integer $width 検証コードの幅
  26. * @param integer $height 検証コードの高さ
  27. * @param integer $codeNum 検証コードの文字Number
  28. * @param integer $codeType 認証コードの文字種 1は数字 2は文字 3は漢字 4は混在
  29. * @param integer $fontSize 認証コードのフォントサイズ
  30. * @param string $fontType 認証コードのフォント種類
  31. * @ param string $imageType 認証コード出力画像タイプ
  32. * @param string $codestr 中国語認証コード内容
  33. +-------------------------- -- ------------------------------------------------ -- --
  34. */
  35. public function __construct($width=100, $height=50, $codeNum=4, $codeType=4, $fontSize= 12, $fontType='heiti. ttf' ,$imageType='jpeg', $codeStr='クソ、平らだ、よく考えてみろ。'){
  36. $this->width = $width ;
  37. $this->height = $height;
  38. $this->codeNum = $codeNum;
  39. $this->codeType = $codeType;
  40. $this->fontSize = $fontSize;
  41. $this -> ;fontType = $fontType;
  42. $this->codeStr = $codeStr;
  43. $this->strNum = strlen($this->codeStr)/3-1;
  44. $this->imageType = $ imageType;
  45. $this->checkCode = $this->getCheckCode();
  46. }
  47. //+---------------------- -------------------------------------------------- -- ----
  48. //* 確認コード文字を生成します
  49. //+-------------------------------- -------------------------------------------------- --
  50. //* @return string
  51. //+------------------------------------- ----------------------------------------------------
  52. public function __toString(){
  53. $string = implode( '', $this->getCheckCode());
  54. $_SESSION["code"]=$string; //セッションに追加
  55. $this->getImage( ); //出力検証コード
  56. return '' ;
  57. }
  58. protected function getCheckCode(){
  59. $string = array(){
  60. case 1:
  61. //数値文字列
  62. $string = array_rand(range(0,9 ), $this->codeNum);
  63. Break;
  64. case 2:
  65. //大きな文字列
  66. $string = array_rand(array_flip(range('A', 'Z' )), $this->codeNum );
  67. Break;
  68. case 3:
  69. //中国語文字列
  70. for($i=0; $i<($this->codeNum); $i++){
  71. $start = mt_rand(0, $this ->strNum);
  72. $string[$i]= self::msubstr($this->codeStr,$start);
  73. }
  74. Break;
  75. case 4:
  76. //混合文字列
  77. for($i=0; $i<($this->codeNum); $i++){
  78. $rand=mt_rand(0,2);
  79. switch ( $rand){
  80. case 0:
  81. $ascii = mt_rand(48,57);
  82. $string[$i] = sprintf('%c',$ascii);
  83. Break;
コードをコピー

検証コード、PHP
このトピックは、2015-11-18 08:23 に Xiaobei によって移動されました


ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!