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.
set cookie
This is the page that set the cookie in the browser.
readcookie.yaws will
read the cookie and report persistent information as
long as the browser session exists.
it will set the cookie
foobar = <x,y,z>; where the
x,y,z string is the textual representation of an
actual erlang pid which will be responsible for
this session.