`
tcspecial
  • 浏览: 895907 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

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 );

 

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();

 

 

 

 

 

  • 大小: 13.6 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics