Jump to content

CURL Login Issue


johne90

Recommended Posts

I am trying to login to youtube via curl but I am getting a page back that says: Your browser's cookie functionality is turned off. Please turn it on.

 

Does anyone know a way around this? Here is the code I am using:

$username = '******';
$password = '******';
$cookie_jar_path = "cookie.txt";
$agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.13) Gecko/2009080315 Ubuntu/9.04 (jaunty) Firefox/3.0.13";

$youtube_login_form = YouTubeLoginPage($cookie_jar_path, $agent); 
$LoggedInPage = SendYouTubeLogin($youtube_login_form, $username, $password, $cookie_jar_path, $agent);
print_r($LoggedInPage); 

function SendYouTubeLogin($youtube_form, $username, $password, $cookie_jar_path, $agent) {
   
$referer = "https://www.google.com/accounts/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http://www.youtube.com/signin?action_handle_signin=true&nomobiletemp=1&hl=en_US&next=%2Findex&hl=en_US&ltmpl=sso";

//Grab Form Code
$pattern = '/(?s)name="GALX"(.*?)value="(.*?)"/';
preg_match($pattern, $youtube_form, $matches); 
$galx = $matches[2];

$post = "ltmpl=sso&continue=";
$post .= urlencode("http://www.youtube.com/signin?action_handle_signin=true&nomobiletemp=1&hl=en_US&next=/");
$post .= "index&service=youtube&uilel=3&ltmpl=sso&hl=en_US&ltmpl=sso&GALX=$galx&Email=$username&Passwd=$password&PersistentCookie=yes&rmShown=1&signIn=Sign in&asts=";

       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL,"https://www.google.com/accounts/ServiceLoginAuth?service=youtube");
       curl_setopt ($ch, CURLOPT_USERAGENT, $agent);
       curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
       curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar_path);
       curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar_path);
       curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
       curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt ($ch, CURLOPT_POSTFIELDS, $post); 
       curl_setopt ($ch, CURLOPT_POST, 1); 
       curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
        
       $syn = curl_exec($ch);
        curl_close($ch);
        
        return $syn;
}

function YouTubeLoginPage($cookie_jar_path, $agent) {
   
$url = "https://www.google.com/accounts/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http://www.youtube.com/signin?action_handle_signin=true&nomobiletemp=1&hl=en_US&next=%2Findex&hl=en_US&ltmpl=sso";
$referer = "http://www.youtube.com/";
           
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_REFERER, $referer); 
       curl_setopt ($ch, CURLOPT_URL, $url);
       curl_setopt ($ch, CURLOPT_USERAGENT, $agent);
       curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar_path);
       curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar_path);
       curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt ($ch, CURLOPT_TIMEOUT, 30);

        $curl_output = curl_exec($ch);
        curl_close($ch);
        $pattern = '/(?s)\<form(.*?)\<\/form\>/';
        preg_match_all($pattern,  $curl_output , $matches);
        
        $youtube_form = $matches[0][1];
       
        return $youtube_form;

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.