cgi-bin.php 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. $descriptorspec = array(
  3. 0 => array("pipe", "r"), // stdin is a pipe that the child will read from
  4. 1 => array("pipe", "w"), // stdout is a pipe that the child will write to
  5. 2 => array("pipe", "w") // stderr is a file to write to
  6. );
  7. $newenv = $_SERVER;
  8. $newenv["SCRIPT_FILENAME"] = $_SERVER["X_SCRIPT_FILENAME"];
  9. $newenv["SCRIPT_NAME"] = $_SERVER["X_SCRIPT_NAME"];
  10. if (is_executable($_SERVER["X_SCRIPT_FILENAME"])) {
  11. $process = proc_open($_SERVER["X_SCRIPT_FILENAME"], $descriptorspec, $pipes, NULL, $newenv);
  12. if (is_resource($process)) {
  13. fclose($pipes[0]);
  14. $head = fgets($pipes[1]);
  15. while (strcmp($head, "\n")) {
  16. header($head);
  17. $head = fgets($pipes[1]);
  18. }
  19. fpassthru($pipes[1]);
  20. fclose($pipes[1]);
  21. fclose($pipes[2]);
  22. $return_value = proc_close($process);
  23. } else {
  24. header("Status: 500 Internal Server Error");
  25. echo("Internal Server Error");
  26. }
  27. } else {
  28. header("Status: 404 Page Not Found");
  29. echo("Page Not Found");
  30. }
  31. ?>