Is there function like php setcookie . If not then how?
EDITED:
yaws_api:setcookie("lang","lang_value", "/"),
yaws_api:find_cookie_val("lang", (A#arg.headers)#headers.cookie),
find_cookie_val returns empty string because setcookie didnt set coockie.
Finally i did it through http header:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.