[英]How to set cookies with 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。
最后我通过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).
该站点提供了一些示例代码用于偏航和设置cookie:http: //yaws.hyber.org/cookies.yaws
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.