admin管理员组文章数量:1390564
I'm trying to get all cookies of a website into an array in PHP. The goal of the script is to enter a website url and let the script check what cookies are set.
I've tried using HTTP_Request like this:
$req = new HTTP_Request($url);
$req->setMethod(HTTP_REQUEST_METHOD_GET);
$req->sendRequest();
$cookies = $req->getResponseCookies();
But this is only returning the server-side set cookies (like a session ID). I would also like to recieve cookies that are set with javascript, like the Google Analytics cookies.
I know this is possible because the website: / is able to do so. To be sure the "cookie-checker" website is really parsing javascript set cookies and not just parsing known javascript source url, I've scanned a test website which wrote a dummy javascript cookie. They detected this cookie succesfully (incl. name, value and expiration date).
Any help would be very much appreciated!
Thanks in advance.
Barry
I'm trying to get all cookies of a website into an array in PHP. The goal of the script is to enter a website url and let the script check what cookies are set.
I've tried using HTTP_Request like this:
$req = new HTTP_Request($url);
$req->setMethod(HTTP_REQUEST_METHOD_GET);
$req->sendRequest();
$cookies = $req->getResponseCookies();
But this is only returning the server-side set cookies (like a session ID). I would also like to recieve cookies that are set with javascript, like the Google Analytics cookies.
I know this is possible because the website: http://www.cookie-checker./ is able to do so. To be sure the "cookie-checker" website is really parsing javascript set cookies and not just parsing known javascript source url, I've scanned a test website which wrote a dummy javascript cookie. They detected this cookie succesfully (incl. name, value and expiration date).
Any help would be very much appreciated!
Thanks in advance.
Barry
Share Improve this question asked Oct 25, 2012 at 11:58 Barry KooijBarry Kooij 4104 silver badges12 bronze badges 2- Is it possible to read cookie of other sites ? Won't it lead to security bleach ? – Prashant Singh Commented Oct 25, 2012 at 12:04
- 1 cookie-checker show you what cookie set the site in input. But its values are not yours – Luca Rainone Commented Oct 25, 2012 at 12:07
2 Answers
Reset to default 5There is no way for a website to access cookies set by another site.
Browsers (have to) make sure this cannot happen.
What the site you mentioned does is make a request to the server and parse (also the javascript) its content.
What you will need to do is make sure that your script parses all the javascript and keeps track of cookies set using it.
The Google Analytics cookie is set by javasvascript and not in the response of the http request. It's impossible with HTTP_Request, it's impossible with PHP...
You need to have an javascript intepreter to get the cookie, or some headless browser (maybe Zombie.js?)
本文标签: javascriptGet cookies of external website with PHPStack Overflow
版权声明:本文标题:javascript - Get cookies of external website with PHP - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744631597a2616571.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论