php下使用curl模拟用户登陆的代码(2)


<?php
 $cookie_jar = tempnam(‘./tmp',‘cookie');
 $ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, ‘');
curl_setopt( $ch, CURLOPT_POST, 1);
 $request = ‘email_address=&password=&action=';
curl_setopt( $ch, CURLOPT_POSTFIELDS,  $request);
//把返回来的cookie信息保存在 $cookie_jar文件中
curl_setopt( $ch, CURLOPT_COOKIEJAR,  $cookie_jar);
//设定返回的数据是否自动显示
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
//设定是否显示头信息
curl_setopt( $ch, CURLOPT_HEADER, false);
//设定是否输出页面内容
curl_setopt( $ch, CURLOPT_NOBODY, false);
curl_exec( $ch);
curl_close( $ch);
//get data after login
 $ch2 = curl_init();
curl_setopt( $ch2, CURLOPT_URL, ‘*****');
curl_setopt( $ch2, CURLOPT_HEADER, false);
curl_setopt( $ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch2, CURLOPT_COOKIEFILE,  $cookie_jar);
 $orders = curl_exec( $ch2);
echo ‘<pre>';
echo strip_tags( $orders);
echo ‘</pre>';
curl_close( $ch2);
?>

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/6ad5974a24388ec4d0897bf6f8c95eed.html