>  기사  >  백엔드 개발  >  php curl方法模拟远程登录

php curl方法模拟远程登录

WBOY
WBOY원래의
2016-06-20 13:02:461269검색

使用curl方法模拟远程登录  * 模拟登录bbs.php100.com

$cookie_file= tempnam('./temp','cookie');

$login_url='http://bbs.php100.com/login.php';
$post_fields='cktime=31536000&step=2&pwuser=这里输入你的用户名&pwpwd=这里输入你的密码';
 
$ch= curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file);
curl_exec($ch);
curl_close($ch);
 
 
$url='http://bbs.php100.com/userpay.php';
$ch= curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
$contents= curl_exec($ch);
preg_match("/<li>金币: (.*)<\/li>/",$contents,$arr);
echo$arr[1];
curl_close($ch);

 


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.