Problem mit CGI in Cpp "This PHP CGI binary was compiled with force-cgi-redirect enabled...."
-
Ich habe nur mal zum Test folgenden CGI in cpp geschrieben:
//--------------------------------------------------------------------------- #include <iostream> #include <algorithm> #include <assert.h> #include <string> #include <list> #include <map> #include <stdlib.h> using namespace std; list<string> split (string str, char tr) { list<string> strElemente; // Ergebnis: Liste von // Teilstrings string::iterator pos1, // Anfang/Ende von pos2; // Teilstrings pos1 = str.begin(); // Beginn eines Teilstrings pos2 = find (pos1, str.end(), tr); // Ende eines Teilstrings while ( pos2 != str.end()) { // Trenner als Ende gefunden assert(*pos2==tr); string elem; // Teilstring copy (pos1, pos2, back_inserter(elem)); // Teilstring kopieren strElemente.push_back(elem); // Teilstring speichern pos1 = pos2; ++pos1; // neuer Anfang hinter altem Ende pos2 = find (pos1, str.end(), tr); // neue Suche } // pos2 zeigt auf das Ende. pos1 zeigt auf den Beginn // des letzten Teilstrings vor dem Ende. // Letzten Teilstring extrahieren: // string last; copy (pos1, str.end(), back_inserter(last)); strElemente.push_back(last); return strElemente; } map< string, string > analyseCgiParam(string str) { list<string> feldListe = split(str, '&'); // in Felder zerlegen map< string,string > felder; // Ergebnis // Felder in Paare aus Feldnamen und Wert splitten // for ( list<string>::iterator i = feldListe.begin(); i != feldListe.end(); ++i){ list<string> feldStr = split(*i, '='); pair< string, string > feld; feld.first = feldStr.front(); // Feldname feldStr.pop_front(); feld.second = feldStr.front(); // Feldwert felder[feld.first] = feld.second; // Paar speichern } return felder; // Abbildung Feld-Name -> Feld-Wert zurueck geben } int main(int argc, char *argv[], char *env[]){ string eingabe; list<string> eingabeElemente; list<string> eingabefertig; //getline(cin,eingabe); //cin >> eingabe; char *geto; geto = getenv("QUERY_STRING"); if( NULL != geto ){ eingabe=geto; } //eingabe=QUERY_STRING; //eingabefertig=split(eingabe, '?'); //list<string>::iterator iword; //iword = eingabefertig.begin(); //iword++; //eingabe=*iword; map < string, string > ueber = analyseCgiParam(eingabe); //ueber>> arry mit den Daten ueber["user"]=satan.... cout << "Content-type: text/html" << endl; // Diese Ausgabe muss jedes cout << endl; // CGI-Programm ales erstes erzeugen cout << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">" << endl; cout << "<html><head><title>Einfacher CGI-C++ TEST</title></head>" << endl; cout << "<body bgcolor=black>" << endl; cout << "<table border=\"1\" width=\"100%\" height=\"217\">" << endl; cout << "<tr><td width=\"103%\" colspan=\"5\" height=\"21\"><center><img src=/wr/dis/banner.gif></td></tr>" << endl; cout << "<tr>" << endl; cout << "<td width=\"20%\" height=\"30\"></td>" << endl; cout << "<td width=\"20%\" height=\"30\"></td>" << endl; cout << "<td width=\"20%\" height=\"30\"></td>" << endl; cout << "<td width=\"20%\" height=\"30\"></td>" << endl; cout << "<td width=\"20%\" height=\"30\"></td>" << endl; cout << "</tr>" << endl; cout << "<tr>" << endl; cout << "<td width=\"20%\" valign=\"top\" >" << endl; cout << "<table border=\"1\" width=\"100%\">" << endl; cout << "<tr>" << endl; cout << "<td width=\"100%\" valign=\"top\"> </td>" << endl; cout << "</tr>" << endl; cout << "<tr>" << endl; cout << "<td width=\"100%\" valign=\"top\"> </td>" << endl; cout << "</tr>" << endl; cout << "<tr>" << endl; cout << "<td width=\"100%\" valign=\"top\"> </td>" << endl; cout << "</tr>" << endl; cout << "</table>" << endl; cout << "</td>" << endl; cout << "<td width=\"141%\" colspan=\"4\" valign=\"top\" > " << endl; // // M I T T E // cout << "Hallo Welt" << endl; cout << "</td>" << endl; cout << "</tr>" << endl; cout << "<tr>" << endl; cout << "<td width=\"103%\" height=\"24\" colspan=\"5\"></td>" << endl; cout << "</tr>" << endl; cout << "</table>" << endl; //cout << ueber["hallo"] << endl; //cout << eingabe << endl; cout << "" << endl; cout << "" << endl; cout << "" << endl; //cin >> trenner; cout << "</body></html>" << endl; }
Auf meiner Windose läuft das mit XAMP auch so wie es soll aber auf meinem Server
(Ubuntu, Apache2) kommt erst diese Fehlermeldung:Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
In der error.log steht dazu:
<p>This PHP CGI binary was compiled with force-cgi-redirect enabled. This
means that a page will only be served up if the REDIRECT_STATUS CGI variable is
set, e.g. via an Apache Action directive.</p>
<p>For more information as to <i>why</i> this behaviour exists, see the <a href="http://php.net/s$
<p>For more information about changing this behaviour or re-enabling this webserver,
consult the installation file that came with this distribution, or visit
<a href="http://php.net/install.windows">the manual page</a>.</p>
Premature end of script headers: eins.cgi
<b>Security Alert!</b> The PHP CGI cannot be accessed directly.ich hoffe ihr könnt mir helfen....
Moritz
-
Der Apache denkt, dass du hier ein PHP Script hast. Unter welchem Pfad liegt deine Binary denn udn wie rufst du sie auf?
-
Shade Of Mine schrieb:
Der Apache denkt, dass du hier ein PHP Script hast. Unter welchem Pfad liegt deine Binary denn udn wie rufst du sie auf?
Ich rufe das Script über den Browser auf mit ..../cgi-bin/eins.cgi
und es lieg dem nach auch in cgi-bin/
-
Zeig mal deine Apache Config eintraege fuer das handlen des cgi-bin verzeichnisses. denn anhand der fehlermeldung sieht es einfach so aus, als wuerde der apache php starten, warum auch immer. also schau mal deine configs durch und deaktiviere mal die ganzen php sachen...
-
Das einzige was da mit CGI drin steht ist
# To use CGI scripts outside /cgi-bin/:
#AddHandler cgi-€.cgi
Und der pfad zum Error Dokument