Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [cURL] formularz i ukryty token
magu112
post
Post #1





Grupa: Zarejestrowani
Postów: 47
Pomógł: 2
Dołączył: 22.07.2009

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


Witam,
Chcę wysłać formularz lecz posiada on ukryty token który po odświeżeniu strony się zmienia a trzeba go też wysłać smile.gif

Tak wygląda token (przykład):
  1. <input name="thxytbwh" type="hidden" value="97a74bf0189ca6444e4ecbc1e8825da2" />

po odświeżeniu strony zmienia się wartość 'name', value jest stały bo to hash

i mam funkcję która by pobrała ten token, tylko jak go pobrać i wysłać bez przeładowania strony?
  1. preg_match("|name=\"(.+?)\".+ value=\"97a74bf0189ca6444e4ecbc1e8825da2\"|", $return, $name_login_hash);


mam coś takiego, z tym że strona się przeładowuje i token się zmienia ;| i nie wiem jak to obejść
  1. $send = new cURL();
  2. $send->get('http://' . $_POST['url'] . '/?action=forgo');
  3.  
  4. // pobieram hasha [jest zakodowany na początku strony w script]
  5. preg_match("|var login_hash = '(.+?)';|", $return, $login_hash);
  6.  
  7. // pobieram name hasha [token]
  8. preg_match("|name=\"(.+?)\".+ value=\"" . $login_hash[1] . "\"|", $return, $name_login_hash);
  9.  
  10. $send->post('http://' . $_POST['url'] . '/?action=forgo', 'subject='.$_POST['subject'].'&text='.$_POST['text'].'&' . $name_login_hash[1] .'='. $login_hash[1].'&send=send');



a przed tym mam jeszcze logowanie na stronie
  1. $login_site = new cURL();
  2. $login_site->get('http://' . $_POST['url']);
  3. $login_site->post('http://' . $_POST['url'], "login=" . $_POST['login'] . "&password=" . $_POST['password'] . "&submit=submit");



funkcja cURL
  1. class cURL {
  2. var $headers;
  3. var $user_agent;
  4. var $compression;
  5. var $cookie_file;
  6. var $proxy;
  7. function cURL($cookies=TRUE,$cookie='cookies.txt',$compression='gzip',$proxy='') {
  8. $this->headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
  9. $this->headers[] = 'Connection: Keep-Alive';
  10. $this->user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13';
  11. $this->compression=$compression;
  12. $this->proxy=$proxy;
  13. $this->cookies=$cookies;
  14. if ($this->cookies == TRUE) $this->cookie($cookie);
  15. }
  16. function cookie($cookie_file) {
  17. if (file_exists($cookie_file)) {
  18. $this->cookie_file=$cookie_file;
  19. } else {
  20. fopen($cookie_file,'w') or $this->error('The cookie file could not be opened. Make sure this directory has the correct permissions');
  21. $this->cookie_file=$cookie_file;
  22. fclose($this->cookie_file);
  23. }
  24. }
  25. function get($url) {
  26. $process = curl_init($url);
  27. curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
  28. curl_setopt($process, CURLOPT_HEADER, 0);
  29. curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
  30.  
  31. if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
  32. if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
  33. curl_setopt($process,CURLOPT_ENCODING , $this->compression);
  34. curl_setopt($process, CURLOPT_TIMEOUT, 30);
  35. if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy);
  36. curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
  37. curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
  38. $return = curl_exec($process);
  39. curl_close($process);
  40. return $return;
  41. }
  42. function post($url,$data) {
  43. $process = curl_init($url);
  44. curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
  45. curl_setopt($process, CURLOPT_HEADER, 1);
  46. curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
  47. if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
  48. if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
  49. curl_setopt($process, CURLOPT_ENCODING , $this->compression);
  50. curl_setopt($process, CURLOPT_TIMEOUT, 30);
  51. if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy);
  52. curl_setopt($process, CURLOPT_POSTFIELDS, $data);
  53. curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
  54. curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
  55. curl_setopt($process, CURLOPT_POST, 1);
  56. $return = curl_exec($process);
  57. curl_close($process);
  58. return $return;
  59.  
  60. }
  61. function error($error) {
  62. echo "<center><div style='width:500px;border: 3px solid #FFEEFF; padding: 3px; background-color: #FFDDFF;font-family: verdana; font-size: 10px'><b>cURL Error</b><br>$error</div></center>";
  63. }
  64. }
Go to the top of the page
+Quote Post

Posty w temacie
- magu112   [cURL] formularz i ukryty token   19.12.2010, 15:46:46
- - Quadina   Ale po co Ci przeładowywanie strony? Popatrz: 1. P...   19.12.2010, 16:22:31
- - magu112   aha. no comments -------- w skrócie, skrypt ma: 1....   19.12.2010, 16:47:25
|- - Rid   Cytat(magu112 @ 19.12.2010, 16:47:25 ...   19.12.2010, 19:16:00
|- - mmdo   Cytat(magu112 @ 19.12.2010, 16:47:25 ...   23.12.2010, 07:29:38
- - Quadina   Kolego, buduje boty od najmniej 5 lat, więc pozwol...   19.12.2010, 17:10:45
- - amii   A nie możesz po prostu: 1. wczytać CURL-em strony...   19.12.2010, 18:15:24
- - magu112   CytatA nie możesz po prostu: 1. wczytać CURL-em st...   19.12.2010, 18:52:56
- - Quadina   Cytatżeby pobrać tokena muszę pobrać stronę łącząc...   19.12.2010, 21:01:06
- - Rid   Za pomocą Ajaxa ,może przesłać formularz bez przeł...   19.12.2010, 21:08:48
- - Quadina   No swojej strony nie przeładujesz, ale załadujesz ...   19.12.2010, 21:12:31
- - magu112   hmmm może prościej będzie na przykładzie captcha ...   22.12.2010, 11:13:45
- - amii   A powinno być tak: wykonując taką czynność się nie...   22.12.2010, 15:00:07
- - CuteOne   Magu:: skąd ten bulwers? Quadina dobrze prawi a ty...   22.12.2010, 23:09:21
- - Quadina   @CuteOne Chwała Ci, Chwala, niech będzie chwała ;-...   22.12.2010, 23:24:23
- - CuteOne   Jemu chyba chodziło o pobranie tokena jako zmienne...   23.12.2010, 18:12:14
- - magu112   Już w ogóle nie kapuje działania tego curla ^^ sie...   29.12.2010, 23:27:21
- - thek   Przecież chłopaki mają racje jak byk! Pobieras...   29.12.2010, 23:53:58
- - marcineck   Witam wszystkich i kłaniam się, gdyż jestem tu now...   5.03.2011, 21:58:39
- - wNogachSpisz   Oszczędze Wam przechwałek, ile lat tworze boty In...   5.03.2011, 23:30:09
|- - fifi209   Cytat(wNogachSpisz @ 5.03.2011, 23:30...   6.03.2011, 11:14:05
- - marcineck   Dzięki za cynk. Wygląda na to, że będę się musiał...   6.03.2011, 10:52:45
- - marcineck   Hej... to może spróbujmy inaczej. Jako że nie mam...   6.03.2011, 12:49:25
- - fifi209   Problem taki, że logowanie przez przeglądarkę nie ...   6.03.2011, 12:59:04
|- - marcineck   Cytat(fifi209 @ 6.03.2011, 12:59:04 )...   6.03.2011, 14:05:30
- - cycofiasz   Za pewne wystarczy obsłużyć ciasteczka bo bez nich...   6.03.2011, 13:03:11
- - fifi209   Gotowe. [PHP] pobierz, plaintext <?php  $...   6.03.2011, 14:20:35


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 22:50