Posted By


ryansobol on 10/31/06

Tagged


Statistics


Viewed 878 times
Favorited by 2 user(s)

send_http_request()


/ Published in: PHP
Save to your folder(s)

Sends a request to a supplied path for a given host. It can send either a GET or POST request and can pass parameters.


Copy this code and paste it in your HTML
  1. function send_http_request($host, $path, $args, $method)
  2. {
  3. if (empty($host) || empty($path) || empty($args) || empty($method)) return false;
  4.  
  5. $temp = array();
  6. foreach ($args as $key => $value) { array_push($temp, "$key=$value"); }
  7.  
  8. $params = implode("&", $temp);
  9. $params_length = strlen($params);
  10.  
  11. $output = <<<END
  12. $method $path HTTP/1.0
  13. Host: $host
  14. User-Agent: PHP-script
  15. Content-Type: application/x-www-form-urlencoded
  16. Content-Length: $params_length
  17.  
  18. $params
  19. END;
  20.  
  21. global $logger; $logger->debug($output);
  22.  
  23. if ($socket = fsockopen($host, 80))
  24. {
  25. $result = fwrite($socket, $output);
  26. fclose($socket);
  27.  
  28. return $result;
  29. }
  30.  
  31. return false;
  32. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.