Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Zachowanie danych POST przy przekierowaniu
-lukasamd-
post
Post #1





Goście







Witam,
chciałbym zrobić tak, że strona obrabiająca formularz automatycznie przekierowuje przez header użytkownika na inny plik, ale zachowuje przekazywanie danych metodą POST.
Jak mogę zachować elementy POSTa podczas takiego przekierowania?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
altruista2
post
Post #2





Grupa: Zarejestrowani
Postów: 127
Pomógł: 32
Dołączył: 8.02.2010

Ostrzeżenie: (0%)
-----


via http://www.hotscripts.com/forums/php/37750...-post-data.html
  1. <?php
  2.  
  3. /**
  4.  * @author
  5.  * @copyright 2007
  6.  */
  7.  
  8. class curl
  9. {
  10. var $channel ;
  11.  
  12. function curl( )
  13. {
  14. $this->channel = curl_init( );
  15. // you might want the headers for http codes
  16. curl_setopt( $this->channel, CURLOPT_HEADER, true );
  17. // you may need to set the http useragent for curl to operate as
  18. curl_setopt( $this->channel, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  19. // you wanna follow stuff like meta and location headers
  20. curl_setopt( $this->channel, CURLOPT_FOLLOWLOCATION, true );
  21. // you want all the data back to test it for errors
  22. curl_setopt( $this->channel, CURLOPT_RETURNTRANSFER, true );
  23. // probably unecessary, but cookies may be needed to
  24. curl_setopt( $this->channel, CURLOPT_COOKIEJAR, 'cookie.txt');
  25. // as above
  26. curl_setopt( $this->channel, CURLOPT_COOKIEFILE, 'cookie.txt');
  27. }
  28. function makeRequest( $method, $url, $vars )
  29. {
  30. // if the $vars are in an array then turn them into a usable string
  31. if( is_array( $vars ) ):
  32. $vars = implode( '&', $vars );
  33. endif;
  34.  
  35. // setup the url to post / get from / to
  36. curl_setopt( $this->channel, CURLOPT_URL, $url );
  37. // the actual post bit
  38. if ( strtolower( $method ) == 'post' ) :
  39. curl_setopt( $this->channel, CURLOPT_POST, true );
  40. curl_setopt( $this->channel, CURLOPT_POSTFIELDS, $vars );
  41. endif;
  42. // return data
  43. return curl_exec( $this->channel );
  44. }
  45. }
  46.  
  47. $curl = new curl( );
  48. // you should not execute both of these, but either way works
  49. echo $curl->makeRequest( 'post', 'http://yourdomain.com/path/to/php.php', 'message=my message goes here' );
  50. echo $curl->makeRequest( 'post', 'http://yourdomain.com/path/to/php.php', array('message=my message goes here', 'type=text') );
  51. ?>


wymaga cURL

Ten post edytował altruista2 17.02.2010, 19:59:26
Go to the top of the page
+Quote Post

Posty w temacie


Closed TopicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 5.10.2025 - 14:19