Ajax Sessions

Hello,
I am trying to write a completely ajax based administration side to a cms software, and I'm having troubles figuring out how to maintain a php session with ajax. Is there any other way other than sending the session id to the client and requiring every xhr call to send the session id? If so, how would I easily do this with CakePHP?
LVL 4
LordZardeckAsked:
Who is Participating?
 
Ray PaseurCommented:
Without seeing the code, I would have to guess it is a cookie-related issue.  The PHP page, if correctly designed, will not care what browsers you are using.  To make any further progress we will need to see what you've got in the code set and have a test case so we can track it on our browsers.  Please post that and we can have a look at it.  Best, ~Ray
0
 
asafadisCommented:
As long as you include "session_start()" and the two pages (the one the client is on and the one being access via AJAX)  are on the same domain, you shouldn't have a problem.  They should both be able to read the same session info.
0
 
Ray PaseurCommented:
The session ID is normally placed on the client by a "setcookie" mechanism which is invoked by the PHP function session_start();  The client sends the cookie back on each subsequent page invocation.  If you do not invoke a new page, the session ID will not get sent back to your server.  But you would still be able to store values in the $_SESSION array, and these values, once set, would be available in every namespace.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Ray PaseurCommented:
One other note... as asafadis wrote, "the same domain" matters.  The same sub-domain matters, too, because PHP's session handler does not automatically let a session persist across www.domain.com and domain.com.  It is a cookie-related issue and can be overridden if cross-subdomain cookies are needed.
0
 
LordZardeckAuthor Commented:
Ok, my I found out that the problem exits only in firefox. When I try to do xhr requests to a php page that requires the user to have been logged in while using Internet Explorer, it works. However, this is not the case for firefox. When I dump the session variable for the xhr request in internet explorer, all the session data is there. Its empty in firefox. What could cause this?
0
 
LordZardeckAuthor Commented:
Since my project is open source, you can have the whole thing. The sql script, if you need it, is in the app/config/sql/cakecms.sql. Its based on the cakePHP framework. Let me know if you need anything else.

http://blackfireweb.com/project_files/cakecms.zip
0
 
LordZardeckAuthor Commented:
By the way, Alot of things don't work :P. I'm working on it, but I really needed to fix the login issue. To get to the problem, go to (assuming your on localhost) http://localhost/admin 
The username is admin and password admin
0
 
LordZardeckAuthor Commented:
So, can ANYONE figure this out?!
0
 
Ray PaseurCommented:
Sorry - I just do not have the time to download and install a CMS, but if you can isolate a small test case, maybe a hundred lines of code, and install the test case for us to see in action on your server, I will be glad to look further.

In Firefox, you can find the cookies with this path.  You should be able to see the session cookie when you visit the site.
TOOLS => OPTIONS => PRIVACY => SHOW COOKIES

Best regards, and please post back if we can see an isolated test case, thanks, ~Ray
0
 
LordZardeckAuthor Commented:
For some reason Firefox kept deleting the session. I set the cookie timeout to expire a whole day later and it seems to have fixed the problem. Sorry for not posting back sooner.
0
 
LordZardeckAuthor Commented:
Led me to fix the problem by changing cookie timeout.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.