Setting Session/Cookie via ajax request made on other website

Posted by user596805 on Stack Overflow See other posts from Stack Overflow or by user596805
Published on 2011-01-31T12:20:41Z Indexed on 2011/01/31 15:25 UTC
Read the original article Hit count: 213

Filed under:
|
|
|
|

Hi,

That's my problem: I have an website, example.com, in which index.html file a introduced a <script src="website.net/js.js"></script> You can see, that this is on other web server. In the js.js I have some data that I want to send to php. For that, I am using Ajax. So, I made a request to "website.net/data.php" using method get. In data.php file everything is ok,I received the value, but I want to set a cookie which value is what I received through ajax. Here is the problem. The setcookie function says that the cookie was set, but when I check in the browser, there's no cookie!

It works fine if the index.html file where I use <script src="website.net/js.js"></script> is hosted on the same domain where I am making the request. If it is on another domain, it doesn't work anymore.

I have read something about Ajax cross site, but I don't want to send something back to example.com. All I want is to send some data from example.com to website.net and then setting a cookie based on that value.

Thank you very much, and sorry for my English!

Later edit: I am not used with this website.

From the example.net I take a single value. On website.net I receive that value, I check if it's not already a cookie set, if it's not, I set it. On the same page, website.net, I use this cookie too.

© Stack Overflow or respective owner

Related posts about php

Related posts about AJAX