Skip to content
Advertisement

CORS Ajax Request: Set-Cookie failing

The CORS scheme is:

AJAX Call from: https://remotewebsite.com/

GET Request to http://localhost/?param=ThisIsImportant

I am using localhost because it still in development.

JavaScript

Response Headers

JavaScript

PHP Pseudo-code

JavaScript

If I enter in http://localhost and visit a script with:

JavaScript

Session is empty. If I check cookies in developer tools, PHPSESSID is different from the one on AJAX response.

I need set the PHPSESSID during AJAX response and kept, and be able to retrieve the SESSION[‘hash’] set on PHP during that AJAX request. Including in another scripts on localhost. Is that possible?

Advertisement

Answer

Found that the $.ajax request should contain

withCredentials: true

crossDomain: true

on server-side, the script need:

JavaScript

that’s it.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement