--- src/modules/standard/mod_cgi.c	2004/07/11 22:07:48	1.1
+++ src/modules/standard/mod_cgi.c	2004/07/11 23:12:07	1.3
@@ -36,6 +36,16 @@
 #include "util_script.h"
 #include "http_conf_globals.h"
 
+#define PHP3HANDLER "/usr/local/bin/php3"
+#define PHP4HANDLER "/usr/local/bin/php4"
+#define PHP5HANDLER "/usr/local/bin/php5"
+#define PHP3 3
+#define PHP4 4
+#define PHP5 5
+#define PHP3TYPE "application/x-httpd-php3"
+#define PHP4TYPE "application/x-httpd-php4"
+#define PHP5TYPE "application/x-httpd-php5"
+
 module MODULE_VAR_EXPORT cgi_module;
 
 /* KLUDGE --- for back-combatibility, we don't have to check ExecCGI
@@ -251,6 +261,8 @@
     int nph;
     int debug;
     char *argv0;
+    char *phphandler;
+    unsigned int phptype;
 };
 
 static int cgi_child(void *child_stuff, child_info *pinfo)
@@ -302,7 +314,11 @@
 #else
     ap_cleanup_for_exec();
 
-    child_pid = ap_call_exec(r, pinfo, argv0, env, 0);
+    if (cld->phptype != 0) {
+       child_pid = ap_call_exec(r, pinfo, cld->phphandler, env, 3);
+    } else {
+       child_pid = ap_call_exec(r, pinfo, argv0, env, 0);
+    }
 #if defined(WIN32) || defined(OS2)
     return (child_pid);
 #else
@@ -344,6 +360,21 @@
 	return DECLINED;
     }
 
+/* do php stuff */
+    cld.phptype = 0;
+    if (r->handler) {
+        if (strcmp(r->handler, PHP4TYPE) == 0) {
+            cld.phptype = PHP4;
+            cld.phphandler = PHP4HANDLER;
+        } else if (strcmp(r->handler, PHP5TYPE) == 0) {
+            cld.phptype = PHP5;
+            cld.phphandler = PHP5HANDLER;
+        } else if (strcmp(r->handler, PHP3TYPE) == 0) {
+            cld.phptype = PHP3;
+            cld.phphandler = PHP3HANDLER;
+        }
+    }
+
     if ((argv0 = strrchr(r->filename, '/')) != NULL)
 	argv0++;
     else
@@ -382,9 +413,10 @@
 	return log_scripterror(r, conf, FORBIDDEN, APLOG_NOERRNO,
 			       "attempt to invoke directory as script");
     if (!ap_suexec_enabled) {
-	if (!ap_can_exec(&r->finfo))
-	    return log_scripterror(r, conf, FORBIDDEN, APLOG_NOERRNO,
-				   "file permissions deny server execution");
+        if (!cld.phptype)
+            if (!ap_can_exec(&r->finfo))
+                return log_scripterror(r, conf, FORBIDDEN, APLOG_NOERRNO,
+                                       "file permissions deny server execution");
     }
 
     if ((retval = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)))
@@ -560,6 +592,9 @@
 {
     {CGI_MAGIC_TYPE, cgi_handler},
     {"cgi-script", cgi_handler},
+    {PHP3TYPE, cgi_handler},
+    {PHP4TYPE, cgi_handler},
+    {PHP5TYPE, cgi_handler},
     {NULL}
 };
 
--- src/main/util_script.c	2004/07/11 22:07:48	1.1
+++ src/main/util_script.c	2004/07/11 23:06:31	1.6
@@ -1206,6 +1218,10 @@
 	}
     }
     else {
+        if (shellcmd == 3) {
+	    execle(argv0, argv0, r->filename, NULL, env);
+	}
+
         if (shellcmd) {
 	    execle(SHELL_PATH, SHELL_PATH, "-c", argv0, NULL, env);
 	}

