如何用雅司设置饼干

时间:2012-02-28 14:28:28

标签: cookies erlang yaws

是否有像php setcookie这样的功能。如果不是那么如何?

编辑:

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

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

2 个答案:

答案 0 :(得分: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).

答案 1 :(得分:1)

此网站提供了偏航和设置Cookie的一些示例代码: http://yaws.hyber.org/cookies.yaws