Advertisement
Guest User

cgi-bin.php

a guest
Jan 27th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <?php
  2.  
  3. $descriptorspec = array(
  4.     0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
  5.     1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
  6.     2 => array("pipe", "w")   // stderr is a file to write to
  7. );
  8.  
  9. $newenv = $_SERVER;
  10. $newenv["SCRIPT_FILENAME"] = $_SERVER["X_SCRIPT_FILENAME"];
  11. $newenv["SCRIPT_NAME"] = $_SERVER["X_SCRIPT_NAME"];
  12.  
  13. if (is_executable($_SERVER["X_SCRIPT_FILENAME"])) {
  14.     $process = proc_open($_SERVER["X_SCRIPT_FILENAME"], $descriptorspec, $pipes, NULL, $newenv);
  15.     if (is_resource($process)) {
  16.         fclose($pipes[0]);
  17.         $head = fgets($pipes[1]);
  18.         while (strcmp($head, "\n")) {
  19.             header($head);
  20.             $head = fgets($pipes[1]);
  21.         }
  22.         fpassthru($pipes[1]);
  23.         fclose($pipes[1]);
  24.         fclose($pipes[2]);
  25.         $return_value = proc_close($process);
  26.     } else {
  27.         header("Status: 500 Internal Server Error");
  28.         echo("Internal Server Error");
  29.     }
  30. } else {
  31.     header("Status: 404 Page Not Found");
  32.     echo("Page Not Found");
  33. }
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement