Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Zdalne logowanie poprzez CURL, Logowanie (zdalne) z użyciem curl
rob_roy
post
Post #1





Grupa: Zarejestrowani
Postów: 29
Pomógł: 1
Dołączył: 21.06.2011

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


Witam,

Niech mnie ktoś nakieruje jak może. Chcę się łączyć z serwerem vimeo i pobierać satystyki oglądanych filmów. Aby móc oglądać statystyki 3ba się jednakże zalogować. Chcę aby skrypt się logował robił to wszystko, mam zamiar go wrzucić w crona.

Do rzeczy


Problem dalej aktualny. Zastosowałem się do wskazówek mortus'a oraz lobopol'a.
Obecna wersja wygląda tak:

  1.  
  2. $log ='login';
  3. $pass='hasło';
  4.  
  5.  
  6. $login_url = 'http://vimeo.com/log_in/';
  7. $url = 'http://vimeo.com/stats/video/25793678';
  8.  
  9. $CNF['cookie_file']='cookie.txt';
  10. $CNF['user_agent']='Mozilla/5.0 (Windows NT 6.0) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30';//$_SERVER["HTTP_USER_AGENT"];
  11. $CNF['referer']='http://vimeo.com/';
  12.  
  13. $agent = $_SERVER["HTTP_USER_AGENT"];
  14. //$header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,;q=0.5";
  15. $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
  16. $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
  17. $header[] = "Cache-Control: max-age=0";
  18. $header[] = "Connection: keep-alive";
  19. $header[] = "Keep-Alive: 300";
  20. $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
  21. $header[] = "Accept-Language: en-us,en;q=0.5";
  22. $header[] = "Pragma: ";
  23.  
  24. foreach ($header as $key => $value)
  25. {
  26. $headers[] = $key.': '.$value;
  27. }
  28.  
  29. //var_dump($_SERVER["HTTP_USER_AGENT"],$headers);
  30.  
  31. //sleep(10);
  32. $ch = curl_init();
  33. # Set some default CURL options
  34. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  35. curl_setopt($ch, CURLOPT_HEADER, true);
  36. curl_setopt($ch, CURLOPT_REFERER, 'http://vimeo.com/');//ze niby przyszedlem z vimeo
  37. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  38. curl_setopt($ch, CURLOPT_URL, $login_url);
  39. curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  40. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  41. curl_setopt($ch, CURLOPT_COOKIEFILE, $CNF['cookie_file']);
  42. curl_setopt($ch, CURLOPT_COOKIEJAR, $CNF['cookie_file']);
  43.  
  44. $page = curl_exec($ch);
  45. $page = strip_tags($page,'<input>');
  46. preg_match('<input type="hidden" id="xsrft" class="xsrft" name="token" value="([a-z|0-9]+)?" />',$page,$token);//znajdz tokena
  47. $query = "sign_in[email]=".$log."&sign_in[password]=".$pass."&token=".$token[1];//zbuduj post query
  48.  
  49. curl_setopt($ch, CURLOPT_POSTFIELDS, $query);//ustawy dane w poscie
  50.  
  51.  
  52. curl_setopt($ch, CURLOPT_REFERER, 'http://vimeo.com/log_in');// a teraz dane poszly z login site'u
  53. curl_setopt($ch, CURLOPT_URL, $url);
  54.  
  55. $content = curl_exec($ch);
  56.  
  57.  
  58. curl_close($ch);
  59. //$content = get_web_page($url);
  60. var_dump($content);


Coraz bliżej z tą różnicą, że mechniz wie, że próbuję oszukiwać, oprócz komunikatu, że Unauthorized to odesłany nagłówek wygląda tak:

  1. HTTP/1.0 401 Unauthorized Date: Thu, 30 Jun 2011 17:01:52 GMT
  2. Server: Apache X-Powered-By: PHP/5.3.5-0.dotdeb.0
  3. Expires: Thu, 30 Jun 2011 05:01:52 GMT
  4. Cache-Control: no-store, no-cache, must-revalidate
  5. Cache-Control: post-check=0, pre-check=0
  6. Set-Cookie: uid=0; expires=Sun, 27-Jun-2021 17:01:52 GMT; path=/; domain=.vimeo.com
  7. Vary: Accept-Encoding
  8. Connection: close Content-Type: text/html; charset=UTF-8


Hmm martwi mnie ten czas... oraz ten cache-control

Any IDEAS?

Ten post edytował rob_roy 30.06.2011, 18:08:43
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 1.10.2025 - 05:12