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 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大