Kaiser69
Kaiser69

Reputation: 430

Session in AJAX calls

I have a problem with my site.

See that pages:

In index.php there is a link. When I press that link, a fancybox2 popup appears. I pass that url to fancybox (/gui/savefeedback.php?somestuff=blablabla)

In that box I have a form with textarea and a submit button. I use the $_SESSION variable to configure some GUI element. In that page, I use jQuery with an AJAX call like /ajaxGateway?action=feedback

AjaxGateway simple parse the command and include /feedback.php?vote=1&comment=aaaaaaaaa

Problem!! In /modules/feedback.php I cannot read $_SESSION variable.

Why?

Upvotes: 0

Views: 2361

Answers (3)

phpKid
phpKid

Reputation: 353

Start every page with if(!isset($_SESSION)) session_start(); If you just do session_start(); it might throw an error if your session is already started on another page.

Upvotes: 0

Basic
Basic

Reputation: 26766

Assuming you're using cookies, then each AJAX request handles cookies in exactly the same way as if you had browsed to the URLs manually...

See here for more information

To confirm everything is working, what happens if you browse manually to those URLs? are you session_start()'ing on every page?

Upvotes: 0

xdazz
xdazz

Reputation: 160863

You need session_start(); at that page(/modules/feedback.php).

Upvotes: 3

Related Questions