Home >php教程 >php手册 >用PHP实现验证码功能

用PHP实现验证码功能

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-22 18:35:411708browse

目前,不少网站为了防止用户利用机器人自动注册、登录、灌水,都采用了验证码技术。所谓验证码,就是将一串随机产生的数字或符号,生成一幅图片,图片里加上一些干扰象素(防止OCR),由用户肉眼识别其中的验证码信息,输入表单提交网站验证,验证成功后才能使用某项功能。

??我们这里展示了如何编写PHP程序实现验证码功能:

??代码一: 

  /*
*  Filename:  authpage.php
  */

  srand((double)microtime()*1000000);

  //验证用户输入是否和验证码一致
    if(isset()) 
    {
        if(strcmp(,)==0)
            echo "验证成功!";
        else
            echo "验证失败!";
    }
  
  //生成新的四位整数验证码
    while((=rand()000)  ?>
    


    
        请输入验证码:

        
        >
        用PHP实现验证码功能 >
    

    


??代码二:

  /*
  *  Filename:  authimg.php
  */

  //生成验证码图片
    Header("Content-type: image/PNG"); 
    srand((double)microtime()*1000000);
     = imagecreate(58,28);
     = ImageColorAllocate(, 0,0,0);
     = ImageColorAllocate(, 255,255,255);
     = ImageColorAllocate(, 200,200,200);
    imagefill(,68,30,);

永久链接:

转载随意!带上文章地址吧。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn