为了实现注册机才写的教程,为了批量注册一个网站,注册带有验证码,幸好是文本验证码,但是有session验证,于是POST必须携带cookie。代码如下。
<?php
class AutoCurl{
private $curl;
private $strCookie;
public $url;
public $data;
function __construct(){
$this->curl=curl_init();
$this->strCookie='tmp.cookie';
if(!file_exists('tmp.cookie')){
$ckfile = fopen("tmp.cookie", "w") or die("Unable to open file!");
fclose($ckfile);
}
}
function __destruct(){
curl_close($this->curl);
}
function CurlGet(){
curl_setopt($this->curl, CURLOPT_URL, $this->url);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true) ;
curl_setopt($this->curl, CURLOPT_BINARYTRANSFER, true) ;
//important
curl_setopt($this->curl,CURLOPT_CONNECTTIMEOUT, 5);
//save_cookie
curl_setopt($this->curl,CURLOPT_COOKIEJAR,$this->strCookie);
$output = curl_exec($this->curl) ;
return $output;
}
function CurlPost(){
curl_setopt($this->curl,CURLOPT_POST,1);
//send_cookie
curl_setopt($this->curl,CURLOPT_COOKIEFILE, $this->strCookie);
curl_setopt($this->curl,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->curl,CURLOPT_URL,$this->url);
curl_setopt($this->curl,CURLOPT_POSTFIELDS,$this->data);
$output = curl_exec($this->curl) ;
return $output;
}
}
//实例化一个会话
$newcurl= new AutoCurl();
//第一步GET获取Cookie和验证码
//设置登录填充的Url
$newcurl->url='http://www.jinghong.in/index.php?m=user&mod=reg';
//发送Get
$result=$newcurl->CurlGet();
//获取验证码
if(preg_match('/\<b\>(.*)\<\/b\>/U',$result, $matches)){
$code=$matches[1];
}
//第二步POST提交注册
//设置登录提交的Url
$newcurl->url='http://www.jinghong.in/index.php?m=user&mod=reg&act=ok';
//设置发送POST数据
$newcurl->data=array("name" =>'a'.rand(pow(10,(6-1)), pow(10,6)-1),"sj" => "1".rand(pow(10,(11-1)), pow(10,11)-1),"email" =>rand(pow(10,(5-1)), pow(10,5)-1)."@qq.com","pass" => rand(pow(10,(7-1)), pow(10,7)-1)."qqcom","bzyzm" => $code);
//发送Post
$result=$newcurl->CurlPost();
var_dump($result);
?> <?php echo similar_text("Hello World","Hello Shanghai"); ?> 2.计算两个字符串的相似度,并返回百分比 <?php similar_text("...
【一】.介绍session由于HTTP是无状态的请求,创建一个会话需要保持必须需要身份标识。当用户第一次访问,PHP会为用户创建一个唯一的sessionid,并将sessionid通过cookie发送给浏览器,并在服务器的临时文件创建一个以sessionid为名的文件用来保存这个sessionid保...
(1).学习目标: 了解常见信号类型(百度PHP支持的信号类型),(2).相关函数学习: (2.1).pcntl_signal函数用于设置一个信号管理器接收进程信号,参数1:信号类型,参数2:回调函数,用于在接收到参数1类型的信...
经常我们下载国外资源容易被墙,可以通过php脚本获取远程文件流然后输出给我们的浏览器来下载。<?php //设置下载文件的url $url = 'https://mirrors.huaweicloud.com/ubuntukylin/ubuntukylin-19....
当我们使用php爬虫采集网站时经常会遇到内容使用ajax异步加载。一般采取的方案是PHP模拟再请求api接口获取数据,但是有时候前端js加密非常麻烦,我们需要将js的加密方法转换为php方法方便curl请求。当然通过了解我们可以通过3种方案解决。第一种:使用phpv8js扩展执行js代码。(pecl...
【一】.无锁场景:多个人购买一件商品,库存减少。商品表:主键 商品名 库存数量 id name stock 1&nb...