[pmwiki-users] Setting and getting cookies in PmWiki
Joachim Durchholz
jo at durchholz.org
Thu Mar 23 03:35:06 CST 2006
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)
Say
$_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 that
> 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.
Caveats:
1) Make sure you're doing something sensible if the $_SESSION entry
wasn't set.
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
$_SESSION.
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.
HTH
Jo
More information about the pmwiki-users
mailing list