Pronblem mit cgi



  • Wenn ich zu erst eine post und dann eine Get anfrage stelle geht alles, wenn ich dies umgekehrt mache aber nicht, habe schon alles mögliche versucht bekomme es aber nicht in den griff:

    cgi.cpp

    #include <iostream> 
    #include <string> 
    #include <fstream> 
    #include "include/libhtml++.h" 
    
    using namespace std; 
    
    bool cgi::anfrage() 
     { 
         query = string(); // Gespeicherten Wert zurücksetzen 
    
         char *request = getenv("REQUEST_METHOD");
         char *env = getenv("QUERY_STRING");
         char *clength = getenv ("CONTENT_LENGTH");
    
         if( request == 0 ) 
         { 
             return false; // Änderung des Rückgabewerts 
         } 
    
    	if(request == std::string("GET")) 
    	{ 
             if (env != 0) 
             { 
                 query = env; 
                 return true;   // Rückgabewert geändert 
             } 
             else 
             { 
                 return false; // Rückgabewert geändert 
             } 
    	}
    
    	if(request == std::string("POST"))
    	{
    
    	 if (clength != 0)
    	{
    	 	getline(cin, query);
    	 	return true;
    	}
    
    		else
    		return false;
    
    	}
    
    	else 
    	return false;
     } 
    
    bool cgi::output(const string& formname) 
    { 
    
    if (anfrage()) 
    { 
    
    f_start = query.find(formname);
    if ( f_start != string::npos)
    {
    
    v_start = query.find("=", f_start); 
    v_start += 1; 
    end = query.find("&", v_start);
    
         if (end != string::npos)
             end -= 1; 
         if (end == string::npos)
             end = query.length();
    
    size = end - v_start;
    queryout = query.substr(v_start, size);
    return true;
    
    }
    else 
    {
    return false;
    }
    
    }
    
    else 
    return false; 
    };
    

    htmlform.cpp

    #include <iostream>
    #include <string>
    #include <fstream>
    #include "include/libhtml++.h"
    
    using namespace std;
    
    void htmlform::starthtml(string sitename)
    {
    cout << "Content-Type:text/html\n\n" << endl
    	<< "<html>" << endl
    	<< "<head>" << endl
    	<< "<title>" << sitename << "</title>" << endl
    	<< "</head>" << endl
    	<< "<body>" << endl;
    }
    
    void htmlform::endhtml()
    {
    cout	<< "</body>" << endl
    	<< "</html>"<< endl;
    }
    
    void htmlform::startform(string methodform)
    {
    cout << "<form action=\"index.cgi\" method=" << methodform << ">" << endl;
    }
    
    void htmlform::endform()
    {
    cout << "</form>" << endl;
    }
    
    void htmlform::formselect (string formselectname, string formselectinput)
    {
    cout << " <select  name=\" " << formselectname << "\"  >" << formselectinput << "> </select>" << endl;
    }
    
    void htmlform::inputsubmit (string submitlabel)
    {
    cout << "<input Type=\"submit\" value=\"" << submitlabel << "\" >" << "</input>" << endl;
    

    libhtml.h

    #include <iostream>
    #include <string>
    #include <sstream>
    
    using namespace std; 
    
    class cgi 
    {
    private:
    
    int f_start;
    int v_start;
    int end;
    int size;
    
    public: 
    string query;
    string queryout;
    bool anfrage(); 
    bool output(const string& formname);
    };
    
    class htmlform
    {
    private:
    
    public:
    void starthtml(string sitename);
    void endhtml();
    void startform(string methodform);
    void endform();
    void inputsubmit( string submitlabel);
    void formselect(string formselectname, string formselectinput);
    };
    
    class htmllayer
    {
    private:
    
    public:
    void createlayer(string layerid);
    void endlayer();
    };
    

    gesamte Anwendung http://rs204cg.rapidshare.com/files/62036788/tuxweblibs.tar.gz


Anmelden zum Antworten