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?