分为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中测试通过!
curl验证码
最新推荐文章于 2023-09-13 22:00:41 发布