I have a jQuery $.ajax code on domain A and a domain B (PHP server).
- Step 1: the user already logged in on PHP server [B],
- Step 2: the user comes to domain A and sends an Ajax request (having only an empty string) to the PHP server
Can I check the session of that user to find his username on the PHP server? Is it possible?
Session cookies would be sent automatically. If the user is logged in to server B before the ajax call is made, the server B session token should be sent along with the ajax request. However, note that ajax calls are subject to the same origin security policy – code loaded from server A will not able to issue ajax calls to server B, as that’s not the same server. There’s methods to work around this, but they’re not as nice as a simple
.ajax()call.