Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Ajax Sessions

Posted on 2009-12-30
11
Medium Priority
?
507 Views
Last Modified: 2012-06-27
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?
0
Comment
Question by:LordZardeck
  • 6
  • 4
11 Comments
 
LVL 11

Expert Comment

by:asafadis
ID: 26151899
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26154646
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26154657
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Author Comment

by:LordZardeck
ID: 26159845
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
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1500 total points
ID: 26161741
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
 
LVL 4

Author Comment

by:LordZardeck
ID: 26202387
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
 
LVL 4

Author Comment

by:LordZardeck
ID: 26202429
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
 
LVL 4

Author Comment

by:LordZardeck
ID: 26325585
So, can ANYONE figure this out?!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26332632
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
 
LVL 4

Author Comment

by:LordZardeck
ID: 26531671
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
 
LVL 4

Author Closing Comment

by:LordZardeck
ID: 31671501
Led me to fix the problem by changing cookie timeout.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question