Home > Backend Development > PHP Tutorial > PHP curl 模拟登陆 获取cookie

PHP curl 模拟登陆 获取cookie

WBOY
Release: 2016-06-13 12:36:32
Original
953 people have browsed it

PHP curl 模拟登陆 获取cookie求助
菜鸟学习使用PHP curl模拟登陆,等陆weiphon论坛时用以下代码成功,登陆www.xiaomi.com就死活成功不了,求助啊。窃以为是cookie获取有问题。麻烦牛人帮忙解决一下。苦思无所得夜不能寐啊!

<br />
<?php<br />
	$cookie_file=tempnam('./temp','cookie');<br />
	$login_url='https://account.xiaomi.com/pass/serviceLoginAuth';<br />
	$post ='user&pwd=&sid=eshop&callback=http%3A%2F%2Forder.xiaomi.com%2Flogin%2Fcallback%3Ffollowup%3Dhttp%253A%252F%252Fwww.xiaomi.com%252F%26sign%3DMjk4NmVlYzNiOWY5YTkwMjExNzg5MjkyNzE3ZmIxOGM4YTBiMDk1Mg%2C%2C&_sign=f%2FKB8SAfmaLZ0s28kcLtBSmZlEM%3D&_json=true'//避免不必要的麻烦 post的具体帐号密码去掉了<br />
<br />
	$ch=$curl=curl_init($login_url);<br />
	curl_setopt($ch,CURLOPT_HEADER,0);<br />
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);<br />
	curl_setopt($ch,CURLOPT_POST,1);<br />
	curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);<br />
	curl_setopt($ch,CURLOPT_POSTFIELDS,$post);<br />
	curl_exec($ch);<br />
	curl_close($ch);<br />
<br />
	$url="http://www.xiaomi.com/index.php";<br />
	$ch=curl_init($url);<br />
	curl_setopt($ch,CURLOPT_HEADER,0);<br />
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);<br />
	curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file);<br />
	$contents=curl_exec($ch);<br />
	curl_close($ch);<br />
	<br />
	<br />
?>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template