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:
$log ='login'; $pass='hasło'; $login_url = 'http://vimeo.com/log_in/'; $url = 'http://vimeo.com/stats/video/25793678'; $CNF['cookie_file']='cookie.txt'; $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"]; $CNF['referer']='http://vimeo.com/'; $agent = $_SERVER["HTTP_USER_AGENT"]; //$header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,;q=0.5"; $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; $header[] = "Cache-Control: max-age=0"; $header[] = "Connection: keep-alive"; $header[] = "Keep-Alive: 300"; $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; $header[] = "Accept-Language: en-us,en;q=0.5"; $header[] = "Pragma: "; foreach ($header as $key => $value) { $headers[] = $key.': '.$value; } //var_dump($_SERVER["HTTP_USER_AGENT"],$headers); //sleep(10); $ch = curl_init(); # Set some default CURL options curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_REFERER, 'http://vimeo.com/');//ze niby przyszedlem z vimeo curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $login_url); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_COOKIEFILE, $CNF['cookie_file']); curl_setopt($ch, CURLOPT_COOKIEJAR, $CNF['cookie_file']); $page = curl_exec($ch); preg_match('<input type="hidden" id="xsrft" class="xsrft" name="token" value="([a-z|0-9]+)?" />',$page,$token);//znajdz tokena $query = "sign_in[email]=".$log."&sign_in[password]=".$pass."&token=".$token[1];//zbuduj post query curl_setopt($ch, CURLOPT_POSTFIELDS, $query);//ustawy dane w poscie curl_setopt($ch, CURLOPT_REFERER, 'http://vimeo.com/log_in');// a teraz dane poszly z login site'u curl_setopt($ch, CURLOPT_URL, $url); $content = curl_exec($ch); curl_close($ch); //$content = get_web_page($url);
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:
HTTP/1.0 401 Unauthorized Date: Thu, 30 Jun 2011 17:01:52 GMT Server: Apache X-Powered-By: PHP/5.3.5-0.dotdeb.0 Expires: Thu, 30 Jun 2011 05:01:52 GMT Cache-Control: no-store, no-cache, must-revalidate Cache-Control: post-check=0, pre-check=0 Set-Cookie: uid=0; expires=Sun, 27-Jun-2021 17:01:52 GMT; path=/; domain=.vimeo.com Vary: Accept-Encoding Connection: close Content-Type: text/html; charset=UTF-8
Hmm martwi mnie ten czas... oraz ten cache-control
Any IDEAS?