Fetching contributors…
Cannot retrieve contributors at this time
62 lines (43 sloc) 1.54 KB
<h2> Read cookie </h2>
out(A) ->
C = H#headers.cookie,
L=case yaws_api:find_cookie_val("foobar", C) of
[] ->
f("<p> No cookie set from the browser, need to "
"visit <a href=\"setcookie.yaws\">setcookie.yaws</a> "
"to set the cookie first ~n", []);
PidStr ->
Pid = list_to_pid(PidStr),
Pid ! {self(), tick},
{Pid, VisitList} ->
f("<p> Yes, I read your cookie "
"You have vistited this page ~w times "
"they were ~n<ol> ~n~s </ol>~n "
"Reloading this page will show the session state ",
lists:map(fun(D) ->
f("<li> ~p~n", [D]) end,
after 500 ->
f("<p> You had a cookie, but the pid handling your sess "
"timedout ...",[])
{html, L}.
The code to read the cookie, is simple, we get the cookie passed to the yaws
code in the #arg structure which is the argument supplied to the out/1 function.
<p>We use the <tt>yaws_api:find_cookie_val/2</tt> function to parse
the raw cookie string passed to us from the browser.
The code is:
out(A) ->
yaws_api:pre_ssi_files(A#arg.docroot, ["readcookie.yaws"]).