PHP CURL标志不起作用

时间:2015-10-21 06:54:35

标签: php curl

我试图通过PHP脚本登录网站获取积分。

但是,以下代码无效。我没有太多使用CURL函数而且不知道为什么。请提供有关如何调试CURL函数的建议。感谢。

<?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.memebox.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.memebox.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.memebox.com/signin/';
curl_setopt($session, CURLOPT_URL, $signinurl);
curl_setopt($session, CURLOPT_HTTPGET, TRUE);
$signin = curl_exec($session);
//print $signin;

0 个答案:

没有答案