dongwei5740 2018-10-12 12:18
浏览 321

如何使用当前站点cookie登录到另一个站点,然后重定向到另一个页面并发出CURL请求?

How can I use current site cookies to login to another site and then redirect to another page ?

I have multiple websites which uses the same external Authenticator.I am trying to make a CURL request from one site to get data from the other site . But I have authentication issue while making the CURL request to other site.

In order to login to another site I need to click on login URL but credentials need not be entered again.

So My actual requirement is :

  1. Use Cookies from current site.

  2. Make a CURL request to another site login URL and login to that site using Cookies from current site.

  3. Make a CURL request to another URL where you can obtain the required data.

I can obtain data from the other site if I am logged into that site in the browser.

My Current Code is as follows:

$agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)";
$loginURL = $url . 'saml_login';
$cleanedURL = $url . 'anotherurl/list';

$curl = curl_init();

//Before making CURl request to $cleanedURL I need to make request to $loginURL(which has a redirect)

curl_setopt($curl, CURLOPT_URL, $cleanedURL);

curl_setopt($curl, CURLOPT_USERAGENT, $agent);

curl_setopt($curl, CURLOPT_FRESH_CONNECT, TRUE);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Cookie: ' . $_SERVER['HTTP_COOKIE']));

curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

curl_setopt($curl, CURLINFO_HEADER_OUT, TRUE);

curl_setopt($curl, CURLOPT_VERBOSE, TRUE);

curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);

$response = curl_exec($curl);

var_dump($response);

All the examples I came across used either used credentials in the header or cookies file which is already exported.

Can any one help me to suggest it.

  • 写回答

1条回答 默认 最新

  • duanjuelu8874 2018-10-12 12:24
    关注

    Cookie sharing is possible by domain. If your application at app.domain.com register a cookie for wildcard domain.com instead of app.domain.com, any subdomain.domain.com will have the access to the cookie key.

    评论

报告相同问题?

悬赏问题

  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题