如何使用curl进行验证码生成和验证
2013-05-05 00:00
405 查看
有时候我们觉得自己生成一个验证码很麻烦,看到别人做的一个验证码又觉得做得相当不错,自己想要在自己的网站上用上这个验证码,一时半会自己做不出来的情况下是不是就一点半法都没有了呢?不是的,这个时候我们可以通过curl从对方的服务器上取得验证码而验证的工作也在对方的服务器上进行,用别人的服务器为自己服务。下面就是相应的代码
a.php
<!DOCTYPE html PUBLIC "-//W3C//DTDXHTML 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//DTDXHTML 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>
a.php
<!DOCTYPE html PUBLIC "-//W3C//DTDXHTML 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//DTDXHTML 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>
相关文章推荐
- 如何使用curl进行验证码生成和验证
- 使用curl进行验证码生成和验证
- 使用Kaptcha进行验证码的生成和验证
- laravel中如何实现验证码验证及使用
- 如何在IIS7上配置 FTP7并使用IIS管理凭据方式进行验证
- laravel中如何实现验证码验证及使用
- 在使用验证控件进行验证后,如何获得焦点!
- 如何对动态创建控件进行验证以及在Ajax环境中的使用
- PHP使用CURL实现对带有验证码的网站进行模拟登录的方法
- 演示使用DOM技术如何根据指定XML,进行相应的修改然后生成新的XML文档
- 如何对动态创建控件进行验证以及在Ajax环境中的使用
- Servlet生成验证码并进行账号密码和验证码的验证登陆!
- 生成验证码且进行登录验证
- PHP使用CURL实现对带有验证码的网站进行模拟登录的方法
- 使用js脚本如何进行客户端验证时出现乱码怎么办?
- Java生成验证码图片并进行验证
- PHP使用CURL实现对带有验证码的网站进行模拟登录的方法
- 如何使用验证控件对DropDownList进行验证
- 如何使用PHP对网站验证码进行破解
- 如何利用深度学习写诗歌(使用Python进行文本生成)