[web2py] Re: cookies related

2013-04-08 Thread dave Zeng
Hi, Anthony,
   Thanks very much,
   It's helpful for the 1st.
   for my 2nd question, setting cookies on browser client could complete 
the task, but need to load another javascript plugin, so i am trying to 
address it in Web2py. 
   Simply speaking, it's a student site, when student practises, the site 
set the current test in cookies(if the student leave and come back later, 
he could start from this test by default, or the student can specify where 
he starts by 'input' field), and get the next test from server, 
continuously.

Thanks
Dave.

On Sunday, April 7, 2013 10:37:25 PM UTC+10, Anthony wrote:

 1. i am using session to transfer user's input from first page to 
 second page via 'redirect', but i don't want to maintain session in 
 filesystem or DB, while seems it's not feasible for web2py, as i tested, 
 there are session files in session directory. so, is it possible to use 
 cookies or session without store the session info?


 If you prefer session data be stored in cookies, from the book:


 


 To *store sessions in cookies* instead you can do:

 session.connect(request,response,cookie_key='yoursecret',compression_level=None)

 Here cookie_key is a symmetric encryption key. compression_level is an 
 optional zlib encryption level.

 While sessions in cookie are often recommended for scalability reason they 
 are limited in size. Large sessions will result in broken cookies.

  

 2. The parameters of the first ajax call in 2nd page come from user's 
 input from the first page, then store and update these parameters to 
 cookies after the ajax call succeeds. continuously, the later ajax calls 
 will use the dynamically-updated parameters which stay in cookies from 
 previous call. So, the problem is: ajax call will use parameters from first 
 page and then use parameters from cookies later. tried to set cookies in 
 the 2nd page with info from 1st page, obviously, it doesn't work.


 It might be more clear if you show some code. Are you setting and 
 retrieving cookie values on the client side via Javascript, or is all that 
 happening on the server (in which case, sessions in cookies as noted above 
 should work)?

 Anthony


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: cookies related

2013-04-07 Thread Anthony


 1. i am using session to transfer user's input from first page to 
 second page via 'redirect', but i don't want to maintain session in 
 filesystem or DB, while seems it's not feasible for web2py, as i tested, 
 there are session files in session directory. so, is it possible to use 
 cookies or session without store the session info?


If you prefer session data be stored in cookies, from the book:

To *store sessions in cookies* instead you can do:

session.connect(request,response,cookie_key='yoursecret',compression_level=None)

Here cookie_key is a symmetric encryption key. compression_level is an 
optional zlib encryption level.

While sessions in cookie are often recommended for scalability reason they 
are limited in size. Large sessions will result in broken cookies.

 

 2. The parameters of the first ajax call in 2nd page come from user's 
 input from the first page, then store and update these parameters to 
 cookies after the ajax call succeeds. continuously, the later ajax calls 
 will use the dynamically-updated parameters which stay in cookies from 
 previous call. So, the problem is: ajax call will use parameters from first 
 page and then use parameters from cookies later. tried to set cookies in 
 the 2nd page with info from 1st page, obviously, it doesn't work.


It might be more clear if you show some code. Are you setting and 
retrieving cookie values on the client side via Javascript, or is all that 
happening on the server (in which case, sessions in cookies as noted above 
should work)?

Anthony

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.