I build a web application using PHP5 and Prototype JS. When logging into the system, the session is filled with an user_id. In the application, the user_id is necessary to determine the user rights....but when I use an Ajax Request the PHP session suddenly is empty! Does anyone know a solution for this problem? Thanks in advance. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
you have to *start* the session at the beginning of the ajax php file <?php session_start(); ajax stuff.... echo "response to browser"; ?> On 10/31/07, mail2rvg <mail2rvg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I build a web application using PHP5 and Prototype JS. When logging > into the system, the session is filled with an user_id. In the > application, the user_id is necessary to determine the user > rights....but when I use an Ajax Request the PHP session suddenly is > empty! > > Does anyone know a solution for this problem? > > Thanks in advance. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
mail2rvg wrote:> I build a web application using PHP5 and Prototype JS. When logging > into the system, the session is filled with an user_id. In the > application, the user_id is necessary to determine the user > rights....but when I use an Ajax Request the PHP session suddenly is > empty! > > Does anyone know a solution for this problem? > > ... >When using php with cookies, the session ID will automatically be sent in the request headers even for Ajax XMLHttpRequests. If you use or allow URL-based php sessions, you''ll have to add the session id to every Ajax request url. untested example: <script language="javascript" type="text/javascript"> //<![CDATA[ var url = ''/ajax_server.php?<?php echo session_name(); ?>=<?php echo session_id(); ?>''; new Ajax.Request(url, { ... }); //]]> </script> - Ken Snyder --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
ah, good point, I hadn''t thought of that one when i replied earlier. Thanks! On 10/31/07, Ken Snyder <kendsnyder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > mail2rvg wrote: > > I build a web application using PHP5 and Prototype JS. When logging > > into the system, the session is filled with an user_id. In the > > application, the user_id is necessary to determine the user > > rights....but when I use an Ajax Request the PHP session suddenly is > > empty! > > > > Does anyone know a solution for this problem? > > > > ... > > > When using php with cookies, the session ID will automatically be sent > in the request headers even for Ajax XMLHttpRequests. If you use or > allow URL-based php sessions, you''ll have to add the session id to every > Ajax request url. > > untested example: > > <script language="javascript" type="text/javascript"> > //<![CDATA[ > var url = ''/ajax_server.php?<?php echo session_name(); ?>=<?php echo > session_id(); ?>''; > new Ajax.Request(url, { ... }); > //]]> > </script> > > > - Ken Snyder > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---