<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:set_cookie("foobar",
                                pid_to_list(P), [{path,"/"}]);
        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:set_cookie("foobar",
                                        pid_to_list(P),
                                        [{path,"/"}]);
                _ ->
                    ok
            end
    end.
</erl>
