Using the set cookie header

Posted on 2004-11-30
Last Modified: 2008-01-09
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(strncmp(pszQueryString,"TEST",4) == 0)
                 pszCookie = getenv("HTTP_COOKIE");

                      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>");
                      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("HTTP/1.0 302 Moved Temporarily\r\n");
          printf("Location: %s\n\n",szLocation);
          printf("Set-Cookie: Cookie=Test\n\n");

Question by:marcus_carey
    LVL 8

    Accepted Solution


    Author Comment

    This,, 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
    Response.Write "Cookies are not supported in this browser"
    End If
    'destroy the object
    Set objBrowser = nothing

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
    When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure ( It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
    The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
    The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now