johne90 Posted January 31, 2010 Share Posted January 31, 2010 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<mpl=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<mpl=sso&hl=en_US<mpl=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<mpl=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 https://forums.phpfreaks.com/topic/190423-curl-login-issue/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.