curl验证码

本文介绍了一个简单的PHP留言系统,包含验证码的生成与验证过程。系统由三个文件组成:验证码输入页面a.php、验证码获取页面i.php及留言提交页面b.php。通过curl模拟浏览器行为获取并提交验证码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

分为3个文件,a.php是验证码输入页面,i.php是用来得到验证码,b.php是用于发表留言的。我用的是http://www.webbeast.cn/?action=show&;id=26&page=1网页进行测试。
注意:请修改php.ini,将php_curl.dll前的注释去掉,然后重启apache服务器。在使用之前,请建一个temp文件夹,这个文件夹是用来存放cookie文件的。因为不能发表重复的贴子,所以在测试之前请到b.php里修改。代码一看就明白的。。。^_^


a.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" c />
      <title>a</title>
      <meta name="generator" c />
      <meta name="author" c />
      <meta name="keywords" c />
      <meta name="description" c />
    </head>
    <body>
    <iframe id='img' src="i.php" scrolling="No" frameborder="0"></iframe>
    <form action="b.php" method="POST">
    <input type="text" name="verify_code" />
    <input type="submit" />
    </form>
    </body>
    </html>



i.php

    <?php
    session_start();
    $cookie_jar=tempnam("temp","webbeast");
    $_SESSION['cookie_jar']=$cookie_jar;
    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,"http://www.webbeast.cn/include/seccode.php");
    curl_setopt($ch,CURLOPT_REFERER,"http://www.webbeast.cn/?action=show&id=26&page=1");
    curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_jar);
    curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_jar);
    curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,false);
    if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'msie')===false)
    {
        header("content-type:image/jpg");
    }
    curl_exec($ch);
    curl_close($ch);
    ?>




b.php

    <?php
    session_start();
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" c />
      <title>b</title>
      <meta name="generator" c />
      <meta name="author" c />
      <meta name="keywords" c />
      <meta name="description" c />
    </head>
    <body>
    <?php
    if(empty($_SESSION['cookie_jar'])) exit();
    $cookie_jar=$_SESSION['cookie_jar'];
    $verify=$_POST['verify_code'];
    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,"http://www.webbeast.cn/post.php");
    curl_setopt($ch,CURLOPT_REFERER,'http://www.webbeast.cn/?action=show&id=26&page=1');
    curl_setopt($ch,CURLOPT_POST,1);
    curl_setopt($ch,CURLOPT_POSTFIELDS,"articleid=26&formhash=2d47d0be&username=cat&password=&url=&content=oh,MyGOD!&clientcode=".$verify."&action=addcomment");
    curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_jar);
    curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_jar);
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,false);
    curl_exec($ch);
    curl_close($ch);
    ?>
    </body>
    </html>



此例子在IE6和FF2.0中测试通过!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值