home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- /* function prototype */
- int CheckBrowser();
-
- main()
- {
- /* Send mime type */
- printf("Content-type: text/html\n\n");
-
- /* Start HTML output */
- printf("<HTML><HEAD>\n");
- printf("<TITLE>CGI Script How-To: Test Script</TITLE>\n");
- printf("</HEAD><BODY>\n");
-
- if (CheckBrowser() == 0)
- {
- /* Unidentified browser, so display an inline GIF image */
- printf("<IMG SRC=\"/images/fish33.gif\">\n");
- }
-
- printf("</BODY></HTML>\n");
- exit(0);
- }
-
-
- /* function CheckBrowser
- *
- * Parses the HTTP_USER_AGENT environment variable and outputs a different
- * output file to a Mozilla or Lynx Web client browser.
- *
- * Returns: 1 if target browser found and output sent,
- * 0 if not found - meaning nothing was done.
- */
-
- int CheckBrowser()
- {
- char* user_agent = getenv("HTTP_USER_AGENT");
-
- if (user_agent == NULL)
- {
- return 0; /* agent not defined -> not defined */
- }
-
- printf("<H2>Browser = %s</H2><P>\n", user_agent);
-
- if (strncmp(user_agent, "Mozilla", 7) == 0)
- {
- /* Display a JPEG image for Netscape browsers */
- printf("<IMG SRC=\"/images/fish33.jpg\">\n");
- return 1; /* agent identified -> Netscape */
- }
- else if (strncmp(user_agent, "Lynx", 4) == 0)
- {
- /* For a text browser show a hyperlink to an image to download it */
- printf("Try this <A HREF=\"/images/fish33.jpg\">link</a> to download an image.\n");
- return 1; /* agent identified -> Lynx */
- }
-
- return 0; /* agent not defined -> other */
- }
-
- /*
- * end of chkagent.c
- */
-