<?php
$CookieFile = dirname(__FILE__).'/cookie.tmp';
if(isset($_GET["img"]))
{
$url = 'http://localhost/livsns/api/verifycode/verifycode.php?id=24';//验证码code
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_COOKIEJAR, $CookieFile);//把返回来的cookie信息保存在文件中
curl_exec($ch);
curl_close($ch);
exit();
}
if(isset($_POST['d']))
{
$b=$_POST[d];//验证码
$p="code=".$b;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"http://localhost/livsns/api/verifycode/verifycode.php?a=check_verify_code");
curl_setopt($ch,CURLOPT_COOKIEFILE,$CookieFile);//同时发送Cookie
curl_setopt($ch,CURLOPT_COOKIEJAR, $CookieFile);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $p);//提交查询信息
$bs = curl_exec($ch);
echo $bs;//输出结果
curl_close($ch);
}else{
?>
<form id="form1" name="form1" method="post" action="">
<img src="?img=true" /><!--由服务器端取图片内容并输出-->
<input type="text" name="d" />
<input type="submit" name="button" id="button" value="sub" />
</form>
<?php }
?>
转载请注明:阿尤博客 » PHP的CURL验证码方法,缺点不支持多用户,有需要的请改进!