[pmwiki-users] Setting and getting cookies in PmWiki
bellavejayaram at cox.net
Thu Mar 23 15:03:48 CST 2006
Thanks a lot. This helps a great deal. After reading the caveats, I
have one question - what can I do in PHP to create a unique code (maybe 3 or
4 digits) for each string I want to store in the list_of_strings and then
decode it back to the string in the generating function? I don't yet know
how large my session data could get but if it does become large, this would
be one way to reduce it, wouldn't it?
Alternatively, if I want to avoid $_SESSION completely, I am wondering if I
could use the (?name) markup that Pm said he might provide as a recipe in
the 'getting form variables' thread - (provided it can be used on more than
one form submit and not just the last submit).
From: Joachim Durchholz [mailto:jo at durchholz.org]
Sent: Thursday, March 23, 2006 2:35 AM
To: Bellave Jayaram
Cc: pmwiki-users at pmichaud.com
Subject: Re: [pmwiki-users] Setting and getting cookies in PmWiki
Bellave Jayaram schrieb:
> Thanks for the offer Jo but I have a limited budget and am more interested
> in the research.
No problem with that.
> In my case, all I need to store is a list of strings (which are anchors in
> PmWiki pages)
$_SESSION ['recipe_name_goes_here'] = list_of_strings;
(Check that this is done between session_start() and
session_write_close() - I'm not 100% sure when exactly PmWiki does that,
but IIRC config.php is inside that time frame.)
> and I need to write the code for checkout which does not need
> to pass anything to PayPal or other outside API but to compose content
> is stored in PmWiki markup.
Use Markup() to have it call a function that generates the HTML you
want. Use Keep() to prevent PmWiki from inadvertently "recognizing"
markup within the HTML you generated.
Alternatively, generate PmWiki markup and don't use keep. This has some
potential pitfalls, but can be just the right thing to do.
The generating function can use $_SESSION ['recipe_name_goes_here'] to
access the data stored on an earlier page.
1) Make sure you're doing something sensible if the $_SESSION entry
2) Sometimes, there's no good place to clear a $_SESSION entry. Make
sure that your recipe doesn't do something ugly if it hits stale data in
3) Don't get carried away over storing stuff in $_SESSION. For each PHP
script that this particular browser will be accessing, $_SESSION will be
loaded from disk at the beginning and stored to disk at the end. This
takes I/O resources, CPU cycles, and RAM. It will be done with every PHP
script that uses sessions, whether it's related to PmWiki or not; and it
will encode and decode all session data, regardless of how much of that
is actually needed. IOW if you have a dozen scripts that each store 10KB
of session data, you're at 120KB session data after the visitor has seen
all of these scripts.
This is nothing to worry about seriously - programmers rarely feel the
temptation to store more than a dozen bytes or so in a session.
More information about the pmwiki-users