前几天玩了一个游戏, 最后一关用了一个trick~(模拟提交数据)
想起了以前自己写的一个模拟登陆北邮人论坛(旧版)的程序(因为首先要找到login的地址,以及需要传递哪些参数,wForum容易满足我的需求):
思路是用CURL模拟登陆一次,得到cookie,然后以后都用着这个cookie去访问论坛。
实现如下:
<?php /** * @author : wusuopubupt * @date : 2013-10-29 * @reference : http://v.youku.com/v_show/id_XMjg5ODQ1MzA0.html * bbs.byr.cn auto login script * * */ $url = "http://bbs.byr.cn/wForum/logon.php"; $field_data = "id=yourid&passwd=yourpasswordCookieDate=2"; // first time curl request,get cookie $ch = curl_init ($url); $cookie_jar = tempnam (".", "cookie"); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie_jar); // save cookie curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.81 Safari/537.36" ); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $field_data); curl_exec ($h); curl_close (); // second time curl request, use formar getted cookie $url = "http://bbs.byr.cn/wForum/index.php"; $ch = curl_init ($url); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie_jar); // use cookie curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0); curl_exec ($ch); curl_close ($ch); ?>
------------------------------------------------------------------------------------
Next Step:
寻找一个可以直接改掉cookie的办法,在浏览器里直接实现登陆。
update:
找到了3中方法:
1.Developer
Tools
(Ctrl-Shift-J or Tools
-> Developer Tools
) ->
Console
输入:document.cookie="keyofcookie=valueofcookie"
2.参考(http://superuser.com/questions/292952/chrome-cookies-folder-in-windows-7)
Google Chrome :
Settings
> Show Advanced Settings > Privacy > Content Settings > Cookies > All Cookies and Site Data
Or simply:
chrome://settings/cookies
WIN7下存放cookie的地址:
C:\Users\Your User Name\AppData\Local\Google\Chrome\User Data\Default\Local Storage
进去修改即可。
3.更为强大的工具:
Edit this Cookie ,直接给chrome装上这个插件,就可以非常非常方便的改了。
附:github地址:https://github.com/wusuopubupt/Edit-This-Cookie