問題概述:
透過php curl模擬登陸一個網站如http://www.aaa.com,透過fiddler抓包分析如下:
1、表單以POST方式提交到http://www.aaa.com /dologin,這裡產生了一個token:xxx,
2、伺服器帶著這個token跳到了以下位址來登陸:https://account.usercenter.com/login?token=xxx&target_url=http://www .aaa.com
;
(注意網域不同,而且是https,此外這個攜帶token的url拷貝到任何電腦都能正常登陸,登陸成功後就會失效)
3、登陸成功後地址重定向到target_url: http://www.aaa.com
問題分析:
我的理解:有一台授權伺服器,任何一台PC電腦存取攜帶有效token的url,PC和伺服器之間透過cookie來維持這個token;
提出問題:
使用php curl該如何實現這個登陸模擬?
以下是我的程式碼:
<code><?php $cookie_file = 'E:\work\cookie.txt'; $login_url = 'http://www.aaa.com/dologin'; $post_fields = 'userName=aa&password=bb&service_key=cc' $post_fields.= '&callback_url=http%3A%2F%2Fwww.aaa.com&hostUrl=http%3A%2F%2Fwww.aaa.com'; $ch = curl_init($login_url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); $contents=curl_exec($ch); curl_close($ch); preg_match('/(https:\/\/account\.usercenter\.com\/tokenLogin[^\s]*)\s*/',$contents,$match); //var_dump($match);die; 此处匹配出携带token的url $ch = curl_init($match[1]); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36 OPR/41.0.2353.46"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $result = curl_exec($ch); curl_close($ch); $url='http://www.aaa.com/1.html'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); //curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36 OPR/41.0.2353.46"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $contents = curl_exec($ch); curl_close($ch); var_dump($contents);//这里输出的页面显示没有登陆成功(这里是问题所在) ?></code>
不知透過cookie能不能實現這種登陸?各位大俠請指點~~
回覆內容:
問題概述:
透過php curl模擬登陸一個網站如http://www.aaa.com,透過fiddler抓包分析如下:
1、表單以POST方式提交到http://www.aaa.com /dologin,這裡產生了一個token:xxx,
2、伺服器帶著這個token跳到了以下位址來登陸:https://account.usercenter.com/login?token=xxx&target_url=http://www .aaa.com
;
(注意網域不同,而且是https,此外這個攜帶token的url拷貝到任何電腦都能正常登陸,登陸成功後就會失效)
3、登陸成功後地址重定向到target_url: http://www.aaa.com
問題分析:
我的理解:有一台授權伺服器,任何一台PC電腦存取攜帶有效token的url,PC和伺服器之間透過cookie來維持這個token;
提出問題:
使用php curl該如何實現這個登陸模擬?
以下是我的程式碼:
<code><?php $cookie_file = 'E:\work\cookie.txt'; $login_url = 'http://www.aaa.com/dologin'; $post_fields = 'userName=aa&password=bb&service_key=cc' $post_fields.= '&callback_url=http%3A%2F%2Fwww.aaa.com&hostUrl=http%3A%2F%2Fwww.aaa.com'; $ch = curl_init($login_url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); $contents=curl_exec($ch); curl_close($ch); preg_match('/(https:\/\/account\.usercenter\.com\/tokenLogin[^\s]*)\s*/',$contents,$match); //var_dump($match);die; 此处匹配出携带token的url $ch = curl_init($match[1]); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36 OPR/41.0.2353.46"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $result = curl_exec($ch); curl_close($ch); $url='http://www.aaa.com/1.html'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); //curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36 OPR/41.0.2353.46"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $contents = curl_exec($ch); curl_close($ch); var_dump($contents);//这里输出的页面显示没有登陆成功(这里是问题所在) ?></code>
不知透過cookie能不能實現這種登陸?各位大俠請指點~~
之前的程式碼我是多次調試如何攜帶cookie,不過應該是始終沒有成功關聯上cookie文件,不知道程式碼方面如何寫攜帶cookie的程式碼。不過後來經過更多次調試後,發現http://www.aaa.com/dologin呼叫後,已經可以登陸本站,這個帶有token的url只是一個sso,為了登陸其它子站。
感謝各位的解答~~
當然可以實現啊,你的理解沒錯。 cookie中保存唯一的token,每次提交的時候都要攜帶token,登入成功後,token立即失效。
按流程有 肯定就是對的

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

stickysessensureuserRequestSarerOutedTothesMeServerForsessionDataConsisterency.1)sessionIdentificeAssificationAssigeaSsignAssignSignSuserServerServerSustersusiseCookiesorUrlModifications.2)一致的ententRoutingDirectSsssssubsequeSssubsequeSubsequestrequestSameSameserver.3)loadBellankingDisteributesNebutesneNewuserEreNevuseRe.3)

phpoffersvarioussessionsionsavehandlers:1)文件:默認,簡單的ButMayBottLeneckonHigh-trafficsites.2)Memcached:高性能,Idealforsforspeed-Criticalapplications.3)REDIS:redis:similartomemememememcached,withddeddeddedpassistence.4)withddeddedpassistence.4)databases:gelifforcontrati forforcontrati,有用

PHP中的session是用於在服務器端保存用戶數據以在多個請求之間保持狀態的機制。具體來說,1)session通過session_start()函數啟動,並通過$_SESSION超級全局數組存儲和讀取數據;2)session數據默認存儲在服務器的臨時文件中,但可通過數據庫或內存存儲優化;3)使用session可以實現用戶登錄狀態跟踪和購物車管理等功能;4)需要注意session的安全傳輸和性能優化,以確保應用的安全性和效率。

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

絕對會話超時從會話創建時開始計時,閒置會話超時則從用戶無操作時開始計時。絕對會話超時適用於需要嚴格控制會話生命週期的場景,如金融應用;閒置會話超時適合希望用戶長時間保持會話活躍的應用,如社交媒體。

服務器會話失效可以通過以下步驟解決:1.檢查服務器配置,確保會話設置正確。 2.驗證客戶端cookies,確認瀏覽器支持並正確發送。 3.檢查會話存儲服務,如Redis,確保其正常運行。 4.審查應用代碼,確保會話邏輯正確。通過這些步驟,可以有效診斷和修復會話問題,提升用戶體驗。

session_start()iscucialinphpformanagingusersessions.1)ItInitiateSanewsessionifnoneexists,2)resumesanexistingsessions,and3)setsasesessionCookieforContinuityActinuityAccontinuityAcconActInityAcconActInityAcconAccRequests,EnablingApplicationsApplicationsLikeUseAppericationLikeUseAthenticationalticationaltication and PersersonalizedContentent。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

記事本++7.3.1
好用且免費的程式碼編輯器

禪工作室 13.0.1
強大的PHP整合開發環境

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。