Jump to content
  • Advertisement
Sign in to follow this  
Thevenin

[web] CGI "Set-Cookie" is big meanie! :(

This topic is 4811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having a great deal of difficulty reading and writing cookies using CGI. My code to write the cookie is this...
printf( "%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10);
printf("Set-cookie: 487657 GM Tyrael                     \n"
       "<html><head><style type=\"text/css\">");
My code to read the cookie is this...
void sCheckLoggedOn()
{
	char *bufCookie;
	int intNumber;
	char chrName[30];

	bufCookie = getenv("HTTP_COOKIE");
	if(bufCookie == NULL){bytLoggedOn = 0; return;}
	else
	{
		/* Extract the account number and password. */
		sscanf(bufCookie,"%d",&intNumber);
		memcpy(chrName,&bufCookie[7], 30);
		chrName[29] = 0;

		/* Lets view the data. */
		printf("%s\n", chrName);
	}
}
The output is really confusing. Sometimes it outputs stuff, and some times it doesn't. Inaddition, it outputs the "Set-cookie" to the screen, I don't want it too! :( Whats happening?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
printf("Set-cookie: 487657 GM Tyrael                     \n"
"<html><head><style type=\"text/css\">");

I'm not sure if this is the issue, but you need two newlines after the last header. What webserver are you running it on?

Share this post


Link to post
Share on other sites
I found the problem.

printf("Set-Cookie: Apples=Oranges\n");
printf( "%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10);


The "Set-Cookie" comes before the text/html declaration.

Thanks anyways. :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!