marcus_carey
asked on
Using the set cookie header
I wrote the following code to test for cookie support. My browser accepts cookies but this code does not detect the cookie it sets. What is the correct method for checking if a browser accepts cookies?
int main(int argc, char *argv[])
{
char *pszCookie;
char *pszQueryString;
char *szLocation = "http://yoursite/cgi-bin/cookie.exe?TEST";
char reply[256];
pszQueryString = getenv("QUERY_STRING");
if(pszQueryString)
{
if(strncmp(pszQueryString, "TEST",4) == 0)
{
pszCookie = getenv("HTTP_COOKIE");
if(pszCookie)
{
if(strcmp(pszCookie,"Cooki e=test") == 0)
{
sprintf(reply,"%s","<HTML> <TITLE>Goo d Cookie!</TITLE><BODY>Your browser supports "\
"the Netscape HTTP Cookie Specification as set by including a Set-Cookie "\
"HTTP Header!</BODY></HTML>");
}
}
else
{
sprintf(reply,"%s","<HTML> <TITLE>Bad Cookie</TITLE><BODY>Sorry, Your browser "\
"doesn't appear to support the cookie protocol. If you believe you have "\
"gotten this message in error... Don't eat cookies</BODY></HTML>");
}
printf("Content-Type: text/html\n\n");
printf("%s",reply);
}
}
else
{
printf("HTTP/1.0 302 Moved Temporarily\r\n");
printf("Location: %s\n\n",szLocation);
printf("Set-Cookie: Cookie=Test\n\n");
}
return(0);
}
int main(int argc, char *argv[])
{
char *pszCookie;
char *pszQueryString;
char *szLocation = "http://yoursite/cgi-bin/cookie.exe?TEST";
char reply[256];
pszQueryString = getenv("QUERY_STRING");
if(pszQueryString)
{
if(strncmp(pszQueryString,
{
pszCookie = getenv("HTTP_COOKIE");
if(pszCookie)
{
if(strcmp(pszCookie,"Cooki
{
sprintf(reply,"%s","<HTML>
"the Netscape HTTP Cookie Specification as set by including a Set-Cookie "\
"HTTP Header!</BODY></HTML>");
}
}
else
{
sprintf(reply,"%s","<HTML>
"doesn't appear to support the cookie protocol. If you believe you have "\
"gotten this message in error... Don't eat cookies</BODY></HTML>");
}
printf("Content-Type: text/html\n\n");
printf("%s",reply);
}
}
else
{
printf("HTTP/1.0 302 Moved Temporarily\r\n");
printf("Location: %s\n\n",szLocation);
printf("Set-Cookie: Cookie=Test\n\n");
}
return(0);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
<%
'declare our variables
Dim blnCookies , objBrowser
'create an instance of browsertype object
Set objBrowser = Server.CreateObject("MSWC.
'set blnCookies to either true or false
blnCookies = objBrowser.cookies
'if true the display this message
If blnCookies = True Then
Response.Write "Cookies are supported in this browser"
'if false display this message
Else
Response.Write "Cookies are not supported in this browser"
End If
'destroy the object
Set objBrowser = nothing
%>