设置 Cookies
向浏览器发送 cookies 是非常简单的。这些 cookies 会在 Content-type 字段之前,与 HTTP 头一起被发送。假设您想设置 UserID 和 Password 为 cookies,设置 cookies 的步骤如下所示:
实例
#include<iostream>usingnamespacestd; intmain(){ cout << "Set-Cookie:UserID=XYZ;\r\n"; cout << "Set-Cookie:Password=XYZ123;\r\n"; cout << "Set-Cookie:Domain=www.w3cschool.cc;\r\n"; cout << "Set-Cookie:Path=/perl;\n"; cout << "Content-type:text/html\r\n\r\n"; cout << "\n"; cout << "\n"; cout << "CGI 中的 Cookies\n"; cout << "\n"; cout << "\n"; cout << "设置 cookies" << endl; cout << "
\n"; cout << "\n"; cout << "\n"; return0;}