/
setcookie.yaws
61 lines (46 loc) · 1.47 KB
/
setcookie.yaws
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
<erl>
session(A, Visits) ->
receive
{From, tick} ->
N = calendar:local_time(),
From ! {self(), [N|Visits]},
session(A, [N|Visits])
after 60000 -> %% keep state for 60 secs only
exit(normal)
end.
out(A) ->
H = A#arg.headers,
C = H#headers.cookie,
case yaws_api:find_cookie_val("foobar", C) of
[] ->
Now = calendar:local_time(),
P = spawn(fun() -> session(A, [Now]) end),
yaws_api:setcookie("foobar",
pid_to_list(P), "/");
PidStr ->
Pid = list_to_pid(PidStr),
case process_info(Pid, messages) of
undefined ->
Now = calendar:local_time(),
P = spawn(fun() ->
session(A, [Now])
end),
yaws_api:setcookie("foobar",
pid_to_list(P), "/");
_ ->
ok
end
end.
</erl>
<html>
<h2> set cookie </h2>
<p>This is the page that set the cookie in the browser.
<a href="readcookie.yaws">readcookie.yaws</a> will
read the cookie and report persistent information as
long as the browser session exists.
<p> it will set the cookie
<tt>foobar = <x,y,z>; </tt> where the
x,y,z string is the textual representation of an
actual erlang pid which will be responsible for
this session.
</html>