-1

i have two sites http://domain1/getcookieshere.php && http://domain2/reqcookie/reqcookieshere.php.

I've echoed $_COOKIE['cookie_name'] on getcookieshere.php. then on the reqcookieshere.php I've used $cookies = file_get_contents('http://ip/domain1/getcookieshere.php');

then I echo the $cookie, but it does not return or display on reqcookieshere.php.

any possible solution? thank you!

Dumbest666
  • 47
  • 3
  • 13
  • Cookies are not shared between domains by default. Have you enabled Cross-Origin-Request-Policy (CORS)? – Obsidian Age Sep 07 '18 at 03:34
  • @ObsidianAge Hi, can I ask if where will i put the headers? is it on the first getcookis.php or reqcookies.php? thank you – Dumbest666 Sep 07 '18 at 03:41

1 Answers1

0

You can't get cookie from another domain. I guess what you need is CURL

<?php
$ch = curl_init('http://www.google.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
$cookies = array();
foreach($matches[1] as $item) {
    parse_str($item, $cookie);
    $cookies = array_merge($cookies, $cookie);
}
var_dump($cookies);

See this reference : how to get the cookies from a php curl into a variable

Does
  • 569
  • 6
  • 24