title: [cURL/PHP] Login with Google Account
body: <p>I'm writing a script which is connected with my google account. But I have problems at the beginning of this. Google blocks my logging. I receive this error: </p>
  
  <blockquote>
    <p>Your browser's cookie functionality is turned off. Please turn it on.</p>
  </blockquote>
  
  <p>Here you have a script: </p>
  
  <pre><code>&lt;?php
  $email = "login";
  $password = "pass";
  
  //curl get
  function curl_get( $curl, $url, $cookiefile) {
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($curl, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1" );
      curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefile);
      curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
      $data = curl_exec($curl);
      return $data;
  }
  
  //curl post
  
  function curl_post( $curl, $url, $cookiefile, $post) {
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
      curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($curl, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1" );
      curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefile);
      curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
      $data = curl_exec($curl);
      return $data;
  }
  
  //cookie file
  $cookiefile = "cookie.txt";
  
  $curl = curl_init( );
  
  //get url to grab GALX &amp; dsh to login
  $data = curl_get( $curl, "https://www.google.com/accounts/ServiceLogin?uilel=3&amp;service=youtube&amp;passive=true&amp;continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252Findex&amp;hl=en_US&amp;ltmpl=sso", $cookiefile);
  
  
  preg_match('/name="GALX"\s*value="(.*?)"/', $data, $galx);
  
  preg_match('/name="dsh" id="dsh"\s*value="(.*?)"/', $data, $dsh);
  
  
  //login
  $data = curl_post( $curl, "https://www.google.com/accounts/ServiceLoginAuth", $cookiefile, "ltmpl=sso&amp;continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252Findex&amp;service=youtube&amp;uilel=3&amp;dsh=$dsh[1]&amp;ltmpl=sso&amp;hl=en_US&amp;ltmpl=sso&amp;timeStmp=&amp;secTok=&amp;GALX=$galx[1]&amp;Email=$email&amp;Passwd=$password&amp;PersistentCookie=yes&amp;rmShown=1&amp;signIn=Sign+in&amp;asts=");
  
  //auth url
  $data = curl_get( $curl, "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&amp;hl=en_US&amp;service=youtube&amp;ltmpl=sso&amp;chtml=LoginDoneHtml", $cookiefile);
  echo $data;
  ?&gt;
  </code></pre>
  
  <p>Cookie file is fine, problem is probably somewhere else.</p>
  
  <p>Thank you in advance for help.
  Mikolaj. </p>