Simulating a cookie-enabled browser in PHP

岁酱吖の 提交于 2019-12-06 04:11:36

For a server-side HTTP client you should use the cURL module. It will allow you to persist cookies across multiple requests. It also does some other neat things like bundling requests (curl_multi) and transparently handling redirects.

When it comes to returning a session to your user, I don't think this is possible. You would need to be able to overwrite the cookies of other domains. This would cause massive security issues, so no browser would implement it.

I've used the Scriptable Browser component from Simpletest for this kind of screen scraping before. It does a pretty good job of simulating a browser.

You don't need to pass the session on to the real client (Even though it may be possible, depending on the site's security level) - You can simply let your PHP-script be a proxy between the target site and your end-user.

Unfortunately, this is not possible unless the websites are on the same domain. Cookies are only valid on the domain they originated from. Also, subdomains count as different domains. Otherwise, (keep in mind I haven't used much php) you could pull the headers out of the response, and copy the cookie out to the client.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!