Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: automatyczne wysylanie formularza
Forum PHP.pl > Forum > PHP
bober0
Witam!
Mam formularz

Kod
<form method="post" action="http://strone.pl/index.php?site=site5">

<input type="text" name="test[arg1]">
<input type="text" name="test[arg2]">

</form>

czy da się zrobić skrypt w php wypełniający formularz i wysyłający go?
z metodą get nie byłoby problemu, ale jak z postem sobie poradzić?
doseo
manual http://pl.php.net/fsockopen

  1. <?php
  2. function httpSocketConnection($host, $method, $path, $data)
  3. {
  4. $method = strtoupper($method);  
  5.  
  6. if ($method == "GET")
  7. {
  8. $path.= '?'.$data;
  9. }  
  10.  
  11. $filePointer = fsockopen($host, 80, $errorNumber, $errorString);
  12.  
  13. if (!$filePointer)
  14. {
  15. logEvent('debug', 'Failed opening http socket connection: '.$errorString.' ('.$errorNumber.')<br/>n');
  16. return false;
  17. }
  18.  
  19. $requestHeader = $method." ".$path." HTTP/1.1rn";
  20. $requestHeader.= "Host: ".$host."rn";
  21. $requestHeader.= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0rn";
  22. $requestHeader.= "Content-Type: application/x-www-form-urlencodedrn";
  23.  
  24. if ($method == "POST")
  25. {
  26. $requestHeader.= "Content-Length: ".strlen($data)."rn";
  27. }
  28.  
  29. $requestHeader.= "Connection: closernrn";
  30.  
  31. if ($method == "POST")
  32. {
  33. $requestHeader.= $data;
  34. }  
  35.  
  36. fwrite($filePointer, $requestHeader);
  37.  
  38. $responseHeader = '';
  39. $responseContent = '';
  40.  
  41. do
  42. {
  43. $responseHeader.= fread($filePointer, 1);
  44. }
  45. while (!preg_match('/rnrn$/', $responseHeader));
  46.  
  47.  
  48. if (!strstr($responseHeader, "Transfer-Encoding: chunked"))
  49. {
  50. while (!feof($filePointer))
  51. {
  52. $responseContent.= fgets($filePointer, 128);
  53. }
  54. }
  55. else
  56. {
  57.  
  58. while ($chunk_length = hexdec(fgets($filePointer)))
  59. {
  60. $responseContentChunk = '';
  61.  
  62. logEventToTextFile('debug', $chunk_length);
  63. $read_length = 0;
  64.  
  65. while ($read_length < $chunk_length)
  66. {
  67. $responseContentChunk .= fread($filePointer, $chunk_length - $read_length);
  68. $read_length = strlen($responseContentChunk);
  69. }
  70.  
  71. $responseContent.= $responseContentChunk;
  72.  
  73. fgets($filePointer);
  74.  
  75. }
  76.  
  77. }
  78.  
  79. logEventToTextFile('debug', $responseContent);
  80.  
  81.  
  82. return chop($responseContent);
  83. }
  84. ?>

użycie:
  1. <?php
  2. $data = 'test[arg1]=tekst1&test[arg2]=tekst2';
  3. httpSocketConnection( 'serwer.pl', 'POST', '/foo/bar.php', $data)
  4. ?>
em_pl
Możesz też skorzystać z klasy zenda:
http://framework.zend.com/manual/en/zend.h...ient.parameters
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.