-1

I am using ajax with PHP I want to create cookie on ajax calling page i have tow domain like domain1.com and domain2.com i have done ajax coding on domain1.com in page test1.php And Create Cookie on domain2.com page test.php

test1.php /// domain1.php

$.ajax({
     url:domain2.com/test.php,
     type:post,
     datatype:json,
     data:'uname=test',
     success:function(data){
     if(data=='ok'){
          window.location='http://domain2.com/cookietest.php'
       }
     }
     });

test.php ///// domain2.com

   $uname=$_POST['uname'];
    if($uname=='test'){
      setcookie('testcookie',$uname,time()+3600);
      echo 'ok';
      }else{
         echo 'not'
        }

I checked cookie value on domain2.com

cookietest.php ///// domain2.com

        <?php
            var_dump($_COOKIE);
                 ?>

I did not found created cookie details. can anyone help me

1 Answers1

0

To create a cookie on domain2.php , you must make a GET request instead of POST request,

see the link below

Cookie for a different domain

Community
  • 1
  • 1
muhammad waqas
  • 742
  • 1
  • 5
  • 20