Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Jak przesłać za pomocą POST tablicę ?
Forum PHP.pl > Forum > Przedszkole
Kamilo
Witam
Tak jak w temacie:
Mam w skrypcie php tablice i chciałbym ją wysłać do innego skryptu za pomocą metody POST, jak to zrobić questionmark.gif
Cysiaczek
Zainteresuj się możliwościami cURL

Pozdrawiam.
Kamilo
A może coś więcej ?
Bo dla mnie cURL jak narazie to magia...

Pozdrawiam
Cysiaczek
Naprawdę tak trudno przeczytać coś, co jest w manualu?
Oto klasa, która jest w manualu i którą byś znalazł, gdybyś chociaż przeczytał :|

  1. <?php
  2. /*
  3. Sean Huber CURL library
  4.  
  5. This library is a basic implementation of CURL capabilities.
  6. It works in most modern versions of IE and FF.
  7.  
  8. ==================================== USAGE ====================================
  9. It exports the CURL object globally, so set a callback with setCallback($func).
  10. (Use setCallback(array('class_name', 'func_name')) to set a callback as a func
  11. that lies within a different class)
  12. Then use one of the CURL request methods:
  13.  
  14. get($url);
  15. post($url, $vars); vars is a urlencoded string in query string format.
  16.  
  17. Your callback function will then be called with 1 argument, the response text.
  18. If a callback is not defined, your request will return the response text.
  19. */
  20.  
  21. class CURL {
  22. var $callback = false;
  23.  
  24. function setCallback($func_name) {
  25. $this->callback = $func_name;
  26. }
  27.  
  28. function doRequest($method, $url, $vars) {
  29. $ch = curl_init();
  30. curl_setopt($ch, CURLOPT_URL, $url);
  31. curl_setopt($ch, CURLOPT_HEADER, 1);
  32. curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  33. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  34. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  35. curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
  36. curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
  37. if ($method == 'POST') {
  38. curl_setopt($ch, CURLOPT_POST, 1);
  39. curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
  40. }
  41. $data = curl_exec($ch);
  42. curl_close($ch);
  43. if ($data) {
  44. if ($this->callback)
  45. {
  46. $callback = $this->callback;
  47. $this->callback = false;
  48. return call_user_func($callback, $data);
  49. } else {
  50. return $data;
  51. }
  52. } else {
  53. return curl_error($ch);
  54. }
  55. }
  56.  
  57. function get($url) {
  58. return $this->doRequest('GET', $url, 'NULL');
  59. }
  60.  
  61. function post($url, $vars) {
  62. return $this->doRequest('POST', $url, $vars);
  63. }
  64. }
  65. ?>


Pozdrawiam.
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.