Welcome to Mike95.com
Home
WELCOME
ABOUT MIKE95.COM
CONTACT ME


Features
FUNNY JOKES
HUMAN FACTOR


C++
Library Source Code:
CGIPARSE
JSTRING
JVECTOR
JSTACK
JHASHTABLE


COM / ASP
MIKE95 COM SVR
- ASP STACK
- ASP QUEUE
- ASP VECTOR


Tutorials:
TEMPLATES
ALGORITHMS
DESIGN PATTERNS


Sample Work
Internet Based
TASK/BUG TRACKER


Visual C++ / MFC
FLIGHT PATH (C++)
MP3 PLAY LIST


Java
JAVA TALK
BAR GRAPH
WEB CAM


Personal
CONTACT ME
RESUME
PICTURES
TRIPS
CGIparse

So you know C++, you know Internet programming...but you don't know how to use this library? This section explains the individual elements required to utilize the CGIparse class.

First, the class is intended to be executed by a browser -- after all that is what CGI is all about anyways. In order for it to be executed by a browser, you should start coding a form. In Figure (1) for example, is a very simple HTML form for a username and password.
Fig. 1 - Sample HTML Form
<html>
<form method="post" action="/bin/CGIparse.exe">
	<input type="text" name="FirstName">
	<input type="text" name="LastName">
	<input type="submit">
</form>
</html>


The form needs to be processed by a CGI program on the server. In the case of the form above, the program is CGIparse.exe and it is located in the a directory called "cgi-bin". The directory where the CGIprogram will exist must have execute permissions. Figure (2) contains some sample C++ code utilizing the CGIparse library to simply dump the values submitted through the form.
Fig. 2 - Sample C++ code
#include "CGIparse.h"

int main()
{
	//initialize the CGIparse object
	CGIparse p;
	
	//the object p contains all the values submitted,
	//dump them to the screen.  Note: mimeType is automatically
	//sent as text/html.
	p.formDump();
	
	return 0;
}


Figure (3) is yet a more detailed example on how security may be granted or denied with the simple password form above.
Fig. 3 - More detailed example
#include <string.h>
#include "CGIparse.h"

const char* PASSWORD = "opensesame";
int main()
{
	//initialize the CGIparse object
	CGIparse p;
	
	//the object p contains all the values submitted,
	char* name = p.valueOf("name");
	char* password = p.valueOf("password");

	CGIparse.printMime();	//send the default mime of text/html
		
	if ( strcmp(password,PASSWORD) == 0 )
	{
		//grant access here
		cout << "Congratulations " << name;
		cout << "! You have access!" << endl;
	}
	else
	{
		//deny access here
		cout << "Sorry, <b>" << password;
		cout << "</b> is not valid." << endl;
	}
	
	
	return 0;
}

(c)2024 Mike95.com / Site Disclaimer
Site Meter