-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadcookie.html
97 lines (62 loc) · 2.39 KB
/
readcookie.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<html>
<h2> Read cookie </h2>
<p> Yes, I read your cookie You have vistited this page 2 times they were
<ol>
<li> {{2024,4,3},{1,4,24}}
<li> {{2024,4,3},{1,4,24}}
</ol>
Reloading this page will show the session state
<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.
<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:
<br><br>
<div class="box"> <pre>
<html>
<h2> Read cookie </h2>
<erl>
out(A) ->
H=A#arg.headers,
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},
receive
{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 ",
[length(VisitList),
lists:map(fun(D) ->
f("<li> ~p~n", [D]) end,
VisitList)
])
after 500 ->
f("<p> You had a cookie, but the pid handling your sess "
"timedout ...",[])
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.
<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:
<erl>
out(A) ->
yaws_api:pre_ssi_files(A#arg.docroot, ["readcookie.yaws"]).
</erl>
</html>
</pre></div>
<br>
</html>