Blogger Information
Blog 31
fans 0
comment 0
visits 14179
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
验证码验证,接口与抽象类
木子木杉
Original
421 people have browsed it

验证码验证

1.安装安装包gregwar/captcha
composer->composer.json中
“require”: {
“gregwar/captcha”: “1.*”
}
命令符中的composer下composer install->composer update
2.login.php

  1. session_start();
  2. require __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
  3. use Gregwar\Captcha\CaptchaBuilder;
  4. $builder = new CaptchaBuilder;
  5. $builder->build();
  6. // $builder->save('out.jpg');
  7. // header('Content-type: image/jpeg');
  8. // $builder->output();
  9. //将验证码的文字信息存放在session中
  10. $_SESSION['phrase'] = $builder->getPhrase();
  11. //后端验证码的验证
  12. if ((strcasecmp($_POST['captcha'], $_SESSION['phrase'])) == 0) {
  13. echo json_encode('验证通过', 320);
  14. } else {
  15. echo json_encode('验证码错误', 320);
  16. }
  17. ?>
  18. <input type="text" name="captcha" placeholder="请输入验证码">
  19. <img src="<?php echo $builder->inline(); ?>" />
  20. <p><?= $_SESSION['phrase'] ?></p>

接口与抽象类

接口是定义,类(抽象类)是实现。
1.接口中公开的均是抽象方法,类属性不能定义在接口中,类常量可以
2.一个工作类必须将接口中的所有方法按照自己的需求去实现,否则该类要定义成抽象类
3.抽象类中可以有抽象方法和普通方法,不能被实例化

  1. interface Idemo
  2. {
  3. const APP_NAME = '咖啡馆';
  4. public static function getInfo(...$info);
  5. public static function cal($a, $b);
  6. }
  7. //抽象类
  8. abstract class aDemo implements Idemo
  9. {
  10. static function getInfo(...$info)
  11. {
  12. return print_r($info, true);
  13. }
  14. }
  15. //工作类
  16. class Work extends aDemo
  17. {
  18. static function cal($a, $b)
  19. {
  20. return pow($a, $b);
  21. }
  22. }
  23. echo Work::getInfo('木子木杉', 35, '正在学习');
  24. //常量最好是以接口的方式去访问
  25. echo Idemo::APP_NAME;
  26. echo aDemo::APP_NAME;
  27. echo aDemo::getInfo('木子木杉', 35, '正在学习');
  28. echo Work::cal(4, 2);
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post