0

I set cookie a file of domain1.com with this method:

<script>
var dominio = '<?php  echo "{$_SERVER['SERVER_NAME']}";  ?>';
document.cookie = 'dominio=' +dominio+'; expires=Wed, 1 Jan 2070 13:47:11 UTC; path=/; domain=domain2.com';
</script>

and get cookie from a file of domain2.com with this method:

<script>
function getCookie(nome) {
  var nome = nome + "=";
  var cookies = document.cookie.split(';');

  for(var i = 0; i < cookies.length; i++) {
    var c = cookies[i].trim();

    if (c.indexOf(nome) == 0) 
      return c.substring(nome.length, c.length);  
  }
}
var url = new String(getCookie('dominio'));
var url2= ("https://"+url+"/vpanel/vpanel.php");
window.location.replace(url2);
</script>

but not working. If I try to write and read the cookie from the same domain it works, on different domains instead of no. Why?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sincerbex
  • 1
  • 3
  • 1
    No, you cannot set cookies across different domains (unless you own both and redirect between the two), see [How to set a cookie for another domain](https://stackoverflow.com/q/6761415/5914775) for more information. – Tom Udding May 20 '17 at 09:21
  • Best is to make a back end for the server – kcode Sep 21 '17 at 16:48

0 Answers0