-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadpcookie.html
85 lines (52 loc) · 1.68 KB
/
readpcookie.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<html>
<h2> Read persistent cookie </h2>
<p> Yes, I read your cookie:it is "1"
Your persistent info is
<pre>
{"Wget/1.24.5",{{2024,4,3},{1,4,25}},{ok,{{127,0,0,1},59488}}}
</pre> </p>
<p>
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.
The code is:</p>
<div class="box">
<pre><html>
<h2> Read persistent cookie </h2>
<erl>
to_integer(S) ->
list_to_integer(string:strip(S, both)).
out(A) ->
H=A#arg.headers,
C = H#headers.cookie,
L=case yaws_api:find_cookie_val("pfoobar", C) of
[] ->
f("<p> No cookie set from the browser, need to "
"visit <a href=\"setpcookie.yaws\">setpcookie.yaws</a> "
"to set the cookie first </p>~n", []);
NumStr ->
Num = to_integer(NumStr),
case ets:lookup(pcookies, {cookie,Num}) of
[{{cookie, Num}, Data}] ->
f("<p> Yes, I read your cookie:it is ~p~n "
"Your persistent info is ~n"
"<pre>~n~p~n</pre> </p>~n", [NumStr, Data]);
[] ->
f("<p> You had a cookie,but the data is gone </p>",[])
end
end,
{html, L}.
</erl>
<p>
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.
The code is:</p>
<erl>
out(A) ->
{ok, B} = file:read_file(A#arg.docroot ++ "/readpcookie.yaws"),
{ehtml,
{'div', [{class, "box"}],
{pre,[], B}}}.
</erl>
</html>
</pre></div>
</html>