[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 514
  • Last Modified:

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,"Cookie=test") == 0)
                      {
                            sprintf(reply,"%s","<HTML><TITLE>Good 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);
}
0
marcus_carey
Asked:
marcus_carey
1 Solution
 
CoolATIGuyCommented:
0
 
marcus_careyAuthor Commented:
This, http://asp.programmershelp.co.uk/chkcookies.php, example works but I guess I worded the question wrong.  I already know that IE supports cookies.  The idea is to test rather cookie support is enabled by setting a cookie value then redirecting to another page to see if the browser saved it.  


<%
'declare our variables
Dim blnCookies , objBrowser
'create an instance of browsertype object
Set objBrowser = Server.CreateObject("MSWC.BrowserType")
'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
%>
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now