最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get cookies of external website with PHP - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 5

There 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?)

发布评论

评论列表(0)

  1. 暂无评论