1. <?php
  2.  
  3. function createPostString($aPostFields) {
  4. foreach ($aPostFields as $key => $value) {
  5. $aPostFields[$key] = urlencode($key) . '=' . urlencode($value);
  6. }
  7. return implode('&', $aPostFields);
  8. }
  9.  
  10. $pattern = '#<input type="hidden" name="form_token" value="(.*?)" />#si'; //token
  11. $pattern1 = '#<input type="hidden" name="lastclick" value="(.*?)" />#si'; //lastclick
  12.  
  13.  
  14. $naglowki = array(
  15. "Host: www.piszemyrazem.foorx.pl",
  16. "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:2.0) Gecko/20100101 Firefox/4.0",
  17. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  18. "Accept-Language: pl,en-us;q=0.7,en;q=0.3",
  19. "Accept-Encoding: gzip, deflate",
  20. "Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7",
  21. "Keep-Alive: 65535",
  22. "Connection: keep-alive",
  23. );
  24.  
  25.  
  26. $naglowki2 = array(
  27. "Host: www.piszemyrazem.foorx.pl",
  28. "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:2.0) Gecko/20100101 Firefox/4.0",
  29. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  30. "Accept-Language: pl,en-us;q=0.7,en;q=0.3",
  31. "Accept-Encoding: gzip, deflate",
  32. "Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7",
  33. "Keep-Alive: 65535",
  34. "Connection: keep-alive",
  35. "Content-type: text/plain",
  36. );
  37.  
  38.  
  39.  
  40.  
  41.  
  42. $postFields['username'] = 'test123';
  43. $postFields['password'] = '123456';
  44. $postFields['login'] = 'Zaloguj się';
  45.  
  46. $postFields2['subject'] = 'czesc jestem nowy :)';
  47. $postFields2['addbbcode'] = '100';
  48. $postFields2['message'] = 'Witam!';
  49. $postFields2['post'] = 'Wyślij';
  50. $postFields2['attach_sig'] = 'on';
  51. $postFields2['poll_title'] = '';
  52. $postFields2['poll_option_text'] = '';
  53. $postFields2['poll_max__options'] = '1';
  54. $postFields2['poll_length'] = '0';
  55.  
  56.  
  57.  
  58.  
  59. //Logowanie
  60. $ch = curl_init();
  61. curl_setopt($ch, CURLOPT_URL, 'http://www.piszemyrazem.foorx.pl/ucp.php?mode=login/');
  62. curl_setopt($ch, CURLOPT_POST, 1);
  63. curl_setopt($ch, CURLOPT_POSTFIELDS, createPostString($postFields));
  64. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookies2.txt');
  65. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookies2.txt');
  66. curl_setopt($ch, CURLOPT_HTTPHEADER, $naglowki);
  67. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  68. curl_exec($ch);
  69. curl_close($ch);
  70.  
  71.  
  72. //Zaloz temat - pobieranie tokenow
  73. $ch = curl_init();
  74. curl_setopt($ch, CURLOPT_URL, 'http://piszemyrazem.foorx.pl/posting.php?mode=post&f=23/');
  75. curl_setopt($ch, CURLOPT_HTTPHEADER, $naglowki);
  76. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookies2.txt');
  77. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookies2.txt');
  78. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  79. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  80. $wynik=curl_exec($ch);
  81. curl_close($ch);
  82.  
  83. preg_match($pattern, $wynik, $matches);
  84. $postFields2['form_token'] = $matches[1] ; //pobieranie tokena
  85.  
  86.  
  87. preg_match('#<form id="postform" method="post" action="./posting.php\?mode=post&f=([0-9]+)&sid=(.*?)">#', $wynik, $matches1);
  88. $sid=$matches1[2]; //pobieranie sid'a
  89.  
  90. preg_match($pattern1, $wynik, $matches2); //pobieranie lastclick i creation time
  91. $postFields2['lastclick'] = $matches2[1];
  92. $postFields2['creation_time'] = $matches2[1];
  93.  
  94. //wysylanie tematu
  95. $ch = curl_init();
  96. curl_setopt($ch, CURLOPT_URL, 'http://piszemyrazem.foorx.pl/posting.php?mode=post&f=23&sid='.$sid);
  97. curl_setopt($ch, CURLOPT_HTTPHEADER, $naglowki2);
  98. curl_setopt($ch, CURLOPT_POST, 1);
  99. curl_setopt($ch, CURLOPT_HEADER, true);
  100. curl_setopt($ch, CURLOPT_POSTFIELDS, createPostString($postFields2));
  101. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookies2.txt');
  102. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookies2.txt');
  103. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  104. $exit=curl_exec($ch);
  105. curl_close($ch);
  106.  
  107. echo $exit;
  108. ?>


Wysyłam chyba wszystko, i wszystko jest dobrze wyciągane [tokeny].
Ale kiedy wysyłam nowy temat to nie działa. Poprostu zwraca mi okno tworzenia nowego tematu.
W końcu wszystko ustawiłem na sztywno i chce napisać temat do pierwszego działu.
Ktoś wie gdzie popełniłem błąd?

//BBcode dodaje w nagłówkach w referer url zebyscie nie mysleli ze to to jest zle

ref

ref