Sudhakar Bavery
Sudhakar Bavery

Reputation: 21

How to Manage Sessions with ajax

Which are the common scenarios where both can not use together ?

Upvotes: 2

Views: 319

Answers (3)

Your Common Sense
Your Common Sense

Reputation: 157872

There is not much difference between AJAX requests and direct ones. Especially from the server-side point of view.

Your PHP script process a request and send out some data. It is really doesn't matter, who did that request - a browser itself or some JS object, running in the browser.

Frankly, AJAX just has nothing to do with sessions - it's PHP's realm

Upvotes: 5

Serty Oan
Serty Oan

Reputation: 1726

Be sure that all you script use the same domain, you can ensure that by positioning it before calling session_start :

session_set_cookie_params(0, "/", example.tld)

Upvotes: 0

Ólafur Waage
Ólafur Waage

Reputation: 70001

If the call is through the same domain (example.com/index.php calls example.com/ajax.php) then it should be enough to call session_start() in both places and the user's session should be used.

Upvotes: 0

Related Questions