Chris Jackson
christopher.jackson at gmail.com
Sun Feb 27 21:29:57 EST 2005
Can you paste the line of code where you call UseSession, passing it the sid. ~= Chris =~ On Sun, 27 Feb 2005 14:43:38 -0500, donnie jones <donniejones18 at gmail.com> wrote: > The javascript uses XMLHttpRequest and from the responseText is > able to get the SID and pass it to the UseSession function. > > I write out the session id in the UseSession function to make sure > that the same session id is being passed, and it works. > However, when I pass that same session id to the Session(req, sid) > it creates another session... > > __ > Donnie > > On Sun, 27 Feb 2005 13:47:31 -0500, Chris Jackson > <christopher.jackson at gmail.com> wrote: > > To add to this: > > > > When UseSession, for example, is called, the parameters (req, sessid) > > get populated via the publisher handler with the values from the > > <form>. So, since sessid is part of the form (<input type="hidden" > > name="sessid"....>), then sessid now get's passed this hidden value > > which came from the GetSID function. Or I could simply grab it by > > saying req.form['sessid']. > > > > ~= Chris =~ > > > > On Sun, 27 Feb 2005 13:43:38 -0500, Chris Jackson > > <christopher.jackson at gmail.com> wrote: > > > So how is the session id getting form GetSID to UseSession? > > > In other words, how does the sessid go from: > > > > > > GetSID => javascript => UseSession > > > > > > req.write simply sends the output to the browser. Does your > > > javascript somehow pick it up? The default parameter of UseSession is > > > (req, sid="") <-blanks. What sets this parameter? UseSession is a > > > handler....not just some regular function. > > > > > > The way I do it: > > > > > > GetSID (...sessid = sess.id()....) # new session => > > > t = psp.PSP(filename = 'blah.psp') # load psp template => > > > t.run(vars={'sessid':sessid, ...}) # pass vars dictionary to template > > > to fill in <%= %> holes => > > > blah.psp (<html>.......... <input type="hidden" name="sessid" > > > value="<%=sessid%>">......</html>) > > > > > > ~= Chris =~ > > > > > > On Sat, 26 Feb 2005 17:33:51 -0500, donnie jones > > > <donniejones18 at gmail.com> wrote: > > > > I am not understanding part of your explanation. > > > > When I do the req.write of the sid, I can then pass it to the UseSession > > > > function, and that UseSession now gets the correct session id. > > > > I req.write the session id in the UseSession function and it is the > > > > same as the session id from the GetSID function.... > > > > > > > > Are you saying that the session itself is lost without saving the sesion > > > > id in the <input hidden> ? I am confused why passing the session id > > > > to the Session(req, sid) shouldn't keep the same session... > > > > > > > > Thanks. > > > > > > > > __ > > > > Donnie > > > > > > > > > > > > On Fri, 25 Feb 2005 16:31:43 -0500, Chris Jackson > > > > <christopher.jackson at gmail.com> wrote: > > > > > This is not quite the same as in the example in the URL. > > > > > > > > > > The example in the URL passes the sessid to an <input hidden...> field > > > > > via PSP templates. And when a function like (def UseSession) is > > > > > called, req.form['sessid'] stores the value from this hidden field. > > > > > That's how the sessid is passed. > > > > > > > > > > In your GetSid function, you simply say req.write, which doesn't > > > > > really do anything but display it, vs. <input hidden...> which > > > > > captures the sessid to be used later. After GetSid ends, your session > > > > > id is lost. > > > > > > > > > > ~= Chris =~ > > > > > > > > > > > > > > > On Fri, 25 Feb 2005 14:53:28 -0500, donnie jones > > > > > <donniejones18 at gmail.com> wrote: > > > > > > def GetSid(req, sid=""): > > > > > > sess = Session(req); > > > > > > if sess.is_new(): > > > > > > sess['u']="user"; > > > > > > sess['p']="password"; > > > > > > sid = sess.id(); > > > > > > sess.save; > > > > > > else: > > > > > > sid = sess.id(); > > > > > > req.write("%s" % sid); > > > > > > return; > > > > > > > > > > > > # list mailboxes > > > > > > def UseSession(req, sid=""): > > > > > > req.write("%s" % sid); > > > > > > sess = Session(req, sid, None, 1800, 0); > > > > > > if sess.is_new(): > > > > > > req.write("<br/>session new<br/>"); > > > > > > sid = sess.id(); > > > > > > else: > > > > > > sess.load(); > > > > > > req.write("%s" % sid); > > > > > > > > > > > > I first call the GetSid from my javascript and I am using > > > > > > XmlHttpRequest that gets the sid from the responseText. > > > > > > Then I call UseSession function with the sid passed to it > > > > > > through the javascript, and I print the sid to make sure the > > > > > > correct id was passed and that works, but after the Session() > > > > > > is ran it always creates a new session, > > > > > > I am not sure why... I used this link > > > > > > http://www.modpython.org/pipermail/mod_python/2005-January/017111.html > > > > > > as an example to follow... > > > > > > > > > > > > Any ideas? > > > > > > Thanks. > > > > > > > > > > > > __ > > > > > > Donnie > > > > > > > > > > > > > > > > > > On Thu, 24 Feb 2005 15:36:43 -0600, Shawn Harrison <harrison at tbc.net> wrote: > > > > > > > donnie jones wrote [02/24/05 2:55 PM]: > > > > > > > > Hello, > > > > > > > > > > > > > > > > Could someone please give me an example of using the Session() > > > > > > > > in modpython for passing data between functions? > > > > > > > > I have been googling, but with no success.. > > > > > > > > > > > > > > > > The problem I am having is that each time I reload a page that calls > > > > > > > > the function like below, it creates a new session. > > > > > > > > > > > > > > > > def test(req): > > > > > > > > sess = Sess(req); > > > > > > > > sid = sess.id(); > > > > > > > > if sess.is_new(): > > > > > > > > req.write("new session %s" % sid); > > > > > > > > else: > > > > > > > > sess.load(); > > > > > > > > req.write("%s" % sess['username']); > > > > > > > > > > > > > > > > I am printing the session id and each time the function is loaded > > > > > > > > I get a new session id, thus I cannot store data in the session > > > > > > > > to use in other functions... > > > > > > > > > > > > > > class BaseSession(req[, sid, secret, timeout, lock, lockfile]) > > > > > > > .. > > > > > > > save() > > > > > > > This method writes session values to storage. > > > > > > > > > > > > > > It doesn't appear that you are doing this. It only writes the data when > > > > > > > you tell it to. > > > > > > > > > > > > > > Shawn Harrison > > > > > > > _______________________________________________ > > > > > > > Mod_python mailing list > > > > > > > Mod_python at modpython.org > > > > > > > http://mailman.modpython.org/mailman/listinfo/mod_python > > > > > > > > > > > > > _______________________________________________ > > > > > > Mod_python mailing list > > > > > > Mod_python at modpython.org > > > > > > http://mailman.modpython.org/mailman/listinfo/mod_python > > > > > > > > > > > > > > > > > > > > >
|