How to add some different cookies using one cgi file? (cgicc lib)

Hello everyone!
I know how to add cookie, but only one. Second one and others will put down to a web-browser page as text. The magic line:
cout << "Content-type:text/html\r\n\r\n";
is switched off. So, I have a question - how to add two or more different cookies using one .cgi file?

This is just some parts from the code, to give a hint:
1
2
3
4
5
HTTPCookie cookie("Count","1");
cout << cgicc::HTTPHTMLHeader().setCookie(cookie);

HTTPCookie cookie2("Indexes", indexes_str);
cout << cgicc::HTTPHTMLHeader().setCookie(cookie2);


Thank you!
Last edited on
It is failing because you are creating a new temporary header object for each cookie. Don't do that.

1
2
3
4
cgicc::HTTPHTMLHeader header;
header.setCookie(cookie1);
header.setCookie(cookie2);
cout << header;

If your cookies are all lined up and ready to go, you can chain the calls to set multiple cookies:

1
2
3
cout << cgicc::HTTPHTMLHeader()
  .setCookie(cookie1)
  .setCookie(cookie2);

You should always read the documentation. https://www.gnu.org/software/cgicc/doc/index.html

Hope this helps.
Last edited on
Thank you! It works now.
Yes, I do https://www.gnu.org/software/cgicc/doc/classcgicc_1_1HTTPCookie.html - but sometimes it's hard to understand.
Everything from GNU is hard to understand. But they do tend to follow a certain pattern in the documentation which, once you get used to it, makes it slightly less hard to follow...

A lot of times it just requires reading through to see if there is a function to do what you are thinking. In this case your problem was more with C++ than the documentation for cgicc, so that made it easier to guess at what it was.

:O)

Registered users can post here. Sign in or register to post.