1

有没有像php setcookie这样的功能。如果没有那怎么办?

编辑:

yaws_api:setcookie("lang","lang_value", "/"),
yaws_api:find_cookie_val("lang", (A#arg.headers)#headers.cookie),

find_cookie_val 返回空字符串,因为 setcookie 没有设置 coockie。

4

2 回答 2

2

最后我通过http头做到了:

out(A) ->
% read 
  yaws_api:find_cookie_val("lang", (A#arg.headers)#headers.cookie),

% send to browser 
  [{header,["Set-Cookie:","lang=ruler;","expires="++to_cookie_expire(60*60*24*30)++";"]},
  {html, ...}]
end.

to_cookie_expire(SecondsToLive) -> 
  Seconds = calendar:datetime_to_gregorian_seconds(calendar:local_time()),
  DateTime = calendar:gregorian_seconds_to_datetime(Seconds +
  SecondsToLive), httpd_util:rfc1123_date(DateTime).
于 2012-02-28T16:43:51.880 回答
1

该站点提供了一些用于 yaws 和设置 cookie 的示例代码:http: //yaws.hyber.org/cookies.yaws

于 2012-02-28T14:31:21.137 回答