Write a message with C ++ to your homepage

xiaoxiao2021-03-06  63

/ * CREATE BY WOUNDEDSOUL * This category is the processing variable and its associated value * I have nothing to do in the summer vacation! Occasionally I saw an article with Delphi Write CGI programs * I want to use C to be a dynamic website! Originally, I want to learn ASP. * Lai Ben is too lazy (why can I use C ? Oh !!! Even this message is the text file to store visitors, but I am going to transfer it to my mysql database. ******* / /// --------------------------- WebTools.h ---------- ------------------- // # include #include class url {public: URL (Char * string); ~ URL ( ); Char * operator [] (const char * varname); int POS (const char * data, char ch); // Returns CH in the first appearance of the first appearance INT POS (Const Char * Data, Const Char * SUB); // Returns the position of the SUB substrings in the first time INT POS (Const Char * DATA, INT BEGIN, CHAR CH); // Returns CH in the string from BeGin first appearance position Char * SUB (Const Char * DATA, INT BEGIN, INT End); // Returns Char * ExtractFromData (const char * data, const char * tag); char * decodeurlstring (const char * urlstr); // The data stream returned by the browser performs decoding char translateHex (CHAR HEX); // Convert to 16 Enciprome Private: char * STR; // Decoded URL Char * Decode_Str; // Decoded URL

}

// The following is a class of implementation

/ / -------------------------------------------------------------------------------------------- -------------------------------------------------- ----------------------------------------- URL :: URL (Char * String ) {Int LEN = Strlen (String); str = new char [len 1]; strcpy (str, string); str [len] = '/ 0'; decode_str = decodeurlString (STR);

}

/ / -------------------------------------------------------------------------------------------- -------------------------------------------------- ----------------------------------------- URL :: ~ URL () { DELETE STR;

Char * URL :: Operator [] (const char * varname) {Return ExtractFromData (Decode_Str, VarName);}

/ / -------------------------------------------------------------------------------------------- -------------------------------------------------- ----------------------------------------- Int Url :: Pos (Const Char * DATA, CHAR CH) {Int length_data = Strlen (data); for (INT i = 0; I

/ / -------------------------------------------------------------------------------------------- -------------------------------------------------- ----------------------------------------- Int Url :: Pos (Const Char * DATA, INT Begin, char ch) {intlene_data = Strlen (data); if (begin <0) Return-5000; for (INT i = begin; i

/ / -------------------------------------------------------------------------------------------- -------------------------------------------------- ------------------------------------------ CHAR * URL :: Sub (const Char * DATA, INT BEGIN, INT End {Int length_data = Strlen (data); int count = end-begin; if (count <0) exit (1); char * TEMP = New Char [count 1]; TEMP [count] = '/ 0'; if (Temp! = NULL) {for (int i = 0; i = 'a') Return (HEX & 0xDF) - 'A' 10; Else Return HEX - '0';}

/ / -------------------------------------------------------------------------------------------- -------------------------------------------------- ---------------------------------------- // ------ ---------------- Decode the URL data returned by the browser ------------------------- -------------------------------------------------- ------------------ Char * URL :: DecodeURLString (const char * URLSTR) {Int len ​​= strlen (urlstr); char * result = new char [len 1] MEMSET (Result, LEN 1, 0); for (int i = 0, j = 0; i <= le; i , j ) {ix (urlstr [i] == ' ') Result [J] = ''; Else IF (Urlstr [i] == '%') {result [j] = translateHex (urlstr [i 1]) * 16 translateHex (Urlstr [i 2]); i = 2;} Else Result [J] = URLSTR [I];} Return Result

/ / -------------------------------------------------------------------------------------------- -------------------------------------------------- ---------------------------------------- // ------ ----------------- From the URL to extract the variable value ------------------------ -------------------------------------------------- ---------------------- CHAR * URL :: ExtractfromData (const char * data, const char * tag) {int position = 0; int position = 0; Position = POS (Data, Tag); if (position> = 0) {position1 = POS (Data, Position, '&');

IF ((Position 1 Strlen (Tag)) == position1) Return null; // Returns null if (Position1> 0) Return Sub (Position 1 Strlen (tag)), position1 ELSE RETURN SUB (DATA, (Position 1 Strlen (Tag)), Strlen (Data)); // Return Null;}}} // ---------- -------------------------------------------------- -------------------------------------------------- ------------------------------ Get method is the easiest! Char * str = getENV ("Query-String") You can read the data returned from the URL from the GET grammar! Below is a POST method! Char * len = GetENV ("Content-length"); intlene = atoi (len); char * str = new char [length 1]; str [length] = '/ 0'; cinret (Str, Length );

转载请注明原文地址:https://www.9cbs.com/read-90331.html

New Post(0)