开发者

curl cookie problem in PHP

开发者 https://www.devze.com 2022-12-17 00:53 出处:网络
as my client needs, I developed a code to login via cURl. login to www.web1.com and store cookies in cookie.txt

as my client needs, I developed a code to login via cURl.

  1. login to www.web1.com and store cookies in cookie.txt

  2. go to www.web2.com and browse a page using that cookie.txt

no problem with www.web2.com

so when i want to do this with www.web3.com, the problem appears.

the www.web3.com uses session and cookies itself and I have to gather and use the开发者_JAVA技巧m.

it means I should have tow series of cookies, first those from www.web1.com , and second those from www.web3.com , then request the www.web3.com/somepage

how I can do that?


You can execute a command line call to curl from php to save cookies to a file like so:

curl -c '/tmp/mycookies.txt' 'http://www.site.com/login.php

Then use those cookies when submiting to the page like so:

curl -b '/tmp/mycookies.txt' -d 'uname=MyLoginName&pass=MyPassword&action=login&x=67&y=11' 'http://www.site.com/login.php'

For more info about these command line flags:

  • http://curl.haxx.se/docs/manpage.html


You can user the following line to get the cookie informations:

curl -k -s -d'user=foo&pass=bar' -D- https://server1.com/login/ -o/dev/null -f

Use shell_exec or exec to run this command. After getting the header information you can parse the cookie information. Use a helper class or write your own parser -> http://framework.zend.com/manual/en/zend.http.cookies.html (Zend_Http_Cookie::fromString) You can store this information in a session and not in a text file. For web3.com grab also the cookie information and save it in the session or the cookie.txt file.

0

精彩评论

暂无评论...
验证码 换一张
取 消