$url='登陆网址';
$post=array(登陆的信息);
function send_http($url, $post, $timeout = 15, $header = array(), $connecttimeout = 5) {
$cookie_file=dirname(__FILE__).'/cookies.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connecttimeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
if ($header){
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
if($post){
if(is_array($post)){
$post = http_build_query($post);
}
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$rs = curl_exec($ch);
$http_info = curl_getinfo($ch);
curl_close($ch);
if($http_info['http_code'] != 200 && $http_info['http_code'] != 302 ){
return false;
}
return $rs;
}
function get_content($url, $cookie) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
$rs = curl_exec($ch);
curl_close($ch);
return $rs;
}
function post_thread($url, $cookie, $post)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
curl_exec($curl);
curl_close($curl);
}
$post = array (
'user_id' => '123456@qq.com',
'password' => '123456',
'goto_page' => 'http://m.app.cn/index.php',
'act' => 'login',
't' => time(),
);
$url = "http://m.app.cn/account/login.php";
$cookie = dirname(__FILE__) . '/cookie_curl.txt';
$url2 = "http://m.app.cn/user/wap/my_index.php";
login_post($url, $cookie, $post);
$thread_info = array(
'action' => 'pub',
'title' => 'Test curl',
'content' => 'Hello, world.',
't' => time(),
);
$pub_thread_url = 'http://m.app.cn/thread/api/pub_thread.php';
$ret = post_thread($pub_thread_url, $cookie, $thread_info);
print_r($ret);
@ unlink($cookie);
?>