1<html>
2
3<h2> Read persistent cookie </h2>
4
5<erl>
6
7to_integer(S) ->
8    list_to_integer(string:strip(S, both)).
9
10out(A) ->
11    H=A#arg.headers,
12    C = H#headers.cookie,
13    L=case yaws_api:find_cookie_val("pfoobar", C) of
14          [] ->
15              f("<p> No cookie set from the browser, need to "
16                "visit <a href=\"setpcookie.yaws\">setpcookie.yaws</a> "
17                "to set the cookie first </p>~n", []);
18          NumStr ->
19              Num = to_integer(NumStr),
20              case ets:lookup(pcookies, {cookie,Num}) of
21                  [{{cookie, Num}, Data}] ->
22                      f("<p> Yes, I read your cookie:it is ~p~n "
23                        "Your persistent info is ~n"
24                        "<pre>~n~p~n</pre> </p>~n", [NumStr, Data]);
25                  [] ->
26                      f("<p> You had a cookie,but the data is gone </p>",[])
27              end
28      end,
29    {html, L}.
30
31</erl>
32
33
34<p>
35The code to read the cookie, is simple, we get the cookie passed to the yaws
36code in the #arg structure which is the argument supplied to the out/1 function.
37The code is:</p>
38
39<erl>
40out(A) ->
41    {ok, B} = file:read_file(A#arg.docroot ++ "/readpcookie.yaws"),
42       {ehtml,
43        {'div', [{class, "box"}],
44        {pre,[], B}}}.
45</erl>
46
47
48</html>
49
50
51
52
53
54
55
56