curl签到代码不工作

WBOY
Lepaskan: 2016-06-06 20:26:20
asal
1136 orang telah melayarinya

老婆用的一个网站有签到功能, 签到10天送5块钱现金券. 老婆大人想要现金券,但是又不想每天去签到, 让我解决. 我尝试了很久也没有搞定,希望高手指点一下.
下面我的代码:

<code><?php $header = array(
    'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36',
    'Content-Type: application/x-www-form-urlencoded',
);

$loginurl = 'http://cn.example.com/customer/account/login/';
$preg_once = '/<input\sname="form_key"\stype="hidden"\svalue="([a-zA-Z0-9_-]+)"/';
$session = curl_init($loginurl);
curl_setopt($session, CURLOPT_HTTPHEADER, $header);
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($session, CURLOPT_NOPROGRESS, false);
curl_setopt($session, CURLOPT_COOKIE, 'cookie.txt');
$login = curl_exec($session);
preg_match($preg_once, $login, $onceArr);
$form_key = $onceArr[1];
//print $form_key;

$data_to_post = array();
$data_to_post['form_key'] = $form_key;
$data_to_post['login[username]']='13111111111@test.com';
$data_to_post['login[password]']='13111111111';
$data_to_post['send']='';
$post_string = http_build_query($data_to_post);
//print $post_string;
$posturl = 'http://cn.example.com/customer/account/loginPost/';
curl_setopt($session, CURLOPT_URL, $posturl);
curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS,$post_string);
curl_setopt($session, CURLOPT_FOLLOWLOCATION, TRUE);
$post = curl_exec($session);
print $post;

$signinurl = 'http://cn.example.com/signin/';
curl_setopt($session, CURLOPT_URL, $signinurl);
curl_setopt($session, CURLOPT_HTTPGET, TRUE);
$signin = curl_exec($session);
//print $signin;</code></code>
Salin selepas log masuk
Salin selepas log masuk

里面的账号密码是新申请的账号,可以登录.
关键是curl函数的参数太多了,而且不太熟悉怎么调试curl的结果. 请高手指点为什么这段代码不工作.

回复内容:

老婆用的一个网站有签到功能, 签到10天送5块钱现金券. 老婆大人想要现金券,但是又不想每天去签到, 让我解决. 我尝试了很久也没有搞定,希望高手指点一下.
下面我的代码:

<code><?php $header = array(
    'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36',
    'Content-Type: application/x-www-form-urlencoded',
);

$loginurl = 'http://cn.example.com/customer/account/login/';
$preg_once = '/<input\sname="form_key"\stype="hidden"\svalue="([a-zA-Z0-9_-]+)"/';
$session = curl_init($loginurl);
curl_setopt($session, CURLOPT_HTTPHEADER, $header);
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($session, CURLOPT_NOPROGRESS, false);
curl_setopt($session, CURLOPT_COOKIE, 'cookie.txt');
$login = curl_exec($session);
preg_match($preg_once, $login, $onceArr);
$form_key = $onceArr[1];
//print $form_key;

$data_to_post = array();
$data_to_post['form_key'] = $form_key;
$data_to_post['login[username]']='13111111111@test.com';
$data_to_post['login[password]']='13111111111';
$data_to_post['send']='';
$post_string = http_build_query($data_to_post);
//print $post_string;
$posturl = 'http://cn.example.com/customer/account/loginPost/';
curl_setopt($session, CURLOPT_URL, $posturl);
curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS,$post_string);
curl_setopt($session, CURLOPT_FOLLOWLOCATION, TRUE);
$post = curl_exec($session);
print $post;

$signinurl = 'http://cn.example.com/signin/';
curl_setopt($session, CURLOPT_URL, $signinurl);
curl_setopt($session, CURLOPT_HTTPGET, TRUE);
$signin = curl_exec($session);
//print $signin;</code></code>
Salin selepas log masuk
Salin selepas log masuk

里面的账号密码是新申请的账号,可以登录.
关键是curl函数的参数太多了,而且不太熟悉怎么调试curl的结果. 请高手指点为什么这段代码不工作.

用开发者工具抓包看看

两个请求为什么要共用一个curl句柄呢?

在 posturl之前重新初始化一个curl句柄

<code>
$session = curl_init();

$posturl = 'http://cn.memebox.com/customer/account/loginPost/';
curl_setopt($session, CURLOPT_URL, $posturl);</code>
Salin selepas log masuk

<code class="php">//调试curl
if(!curl_errno($ch))
{
 $info = curl_getinfo($ch);
}</code>
Salin selepas log masuk
Label berkaitan:
php
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan