1
<?php
$email = "";
$password = "";
function searchstring($string_to_search,$string_start,$string_end)
{
if (strpos($string_to_search,$string_start)===false)
return false;
if (strpos($string_to_search,$string_end)===false)
return false;
$start=strpos($string_to_search,$string_start)+strlen($string_start);$end=strpos($string_to_search,$string_end,$start);
$return=substr($string_to_search,$start,$end-$start);
return $return;
}
//curl get
function curl_get($ch, $url, $cookiefile) {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
return $data;
}
//curl post
function curl_post($ch, $url, $cookiefile, $post) {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
return $data;
}
//cookie file
$cookiefile = "cookie.txt";
$ch = curl_init();
//get url to grab GALX to login
$data = curl_get($ch, "https://www.google.com/accounts/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252Findex&hl=en_US<mpl=sso", $cookiefile);
//grab galx token needed to login
preg_match('/name="GALX"\s*value="(.*?)"/', $data, $galx);
//login
$thegalx = $galx[1];
$post_elements=array('ltmpl'=>'sso',
'continue'=>'http://www.youtube.com/signin?action_handle_signin=true&nomobiletemp=1&hl=en_US&next=%2Findex',
'next'=>'/',
'service'=>'youtube',
'uilel'=>3,
'ltmpl'=>'sso',
'hl'=>'en_US',
'ltmpl'=>'sso',
'GALX'=>$thegalx,
'Email'=>$email,
'Passwd'=>$password,
'PersistentCookie'=>'yes',
'rmShown'=>1,
'signIn'=>'Sign in',
'asts'=>false,
);
$login = curl_post($ch, "https://www.google.com/accounts/ServiceLoginAuth", $cookiefile, $post_elements);
//auth url
$data = curl_get($ch, "https://www.google.com/accounts/CheckCookie?continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252Findex&hl=en_US&service=youtube<mpl=sso&chtml=LoginDoneHtml", $cookiefile);
//grab auth url
$authurl=html_entity_decode(urldecode(str_replace('\x', '%', searchstring($data,'location.replace("','"'))));
//print_r($authurl);
//hit auth url to login
curl_get($ch, $authurl, $cookiefile);
//$ch = curl_init();
//$data = curl_get($ch, "http://www.youtube.com/watch?v=VBqVfmWM1og", $cookiefile);
//print $data;
//doesnt work
// youtube
$datayoutube = curl_get($ch, "http://www.youtube.com/", $cookiefile);
print_r($datayoutube);
curl_close($ch);
?>
嗨,具有捲曲
我已經能夠通過抓住GALX值成功登錄到YouTube的一些問題。當我打印出位於代碼底部的http://youtube.com的內容時,它顯示正常,它顯示我已登錄..但如果要打印出視頻網址的內容(在代碼中註釋如下)該頁面只是空白和白色..這讓我瘋狂,任何人都知道爲什麼會發生這種情況?
是否打開了錯誤報告? – 2011-02-08 10:22:44