Cookie设置

一. 比较

document.cookie = "a=b; max-age=3600; path=/;";

Set-Cookie: a=b; max-age=3600; path=/; 

第一种是在客户端通过js设置,随请求传递至服务端,php可通过$_COOKIE获取。

第二种是在服务端设置,通过在http头部添加多个Set-Cookie字段实现。

 

二. 语言实现 

Cookie secondName = new Cookie( "second", "val-2" );
secondName.setMaxAge( 60*60*1 );
secondName.setPath( "/" );
rep.addCookie( secondName );
扫描二维码关注公众号,回复: 295171 查看本文章
setcookie('age', 50, time() + 10, '/');

CGI:

cgi没有java/php现成API调用,可在http头部添加多个Set-Cookie来实现。

std::string sContent;
sContent.assign("Set-Cookie: qqopenid=");
sContent.append("11").append(";");
sContent.append("exprires=").append(THOR_COOKIE_TIME).append(";");
sContent.append("domain=").append("xxx.com;");
sContent.append("path=/;");

sContent.append("\r\nSet-Cookie: token=");
sContent.append("22").append(";");
sContent.append("exprires=").append(THOR_COOKIE_TIME).append(";");
sContent.append("domain=").append("xxx.com;");
sContent.append("path=/;");

ClearSilver接口:

// 方法一:

hdf_set_value( m_pCgi->hdf, "cgiout.other.Set-Cookie", sContent.c_str() );

// 方法二:

cgi_cookie_set();

猜你喜欢

转载自tcspecial.iteye.com/blog/2395828
今日推荐