title: How to Single Signon authentication for wordpress to drupal?
body: <p>Once user logged in wordpress drupal site also should automatically loggedin. if user not available in drupal site it should insert and login into drupal. I have tried to set cookies to drupal site. but i cant resolve it. please check with my below code. </p>
  
  <pre><code>function drupal_authentication() {   
  
  
      $user_login = $_REQUEST["username"];
      $user_pass = $_REQUEST["password"];
  
      $login_url = 'http://xxxx.com/drup/user/login';
  
      // Preparing postdata for wordpress login
      $data = "name=".$user_login."&amp;pass=".$user_pass."&amp;form_id=user_login&amp;sso=1" ;
  
      $cookie_file= rand().'.txt';
  
      $http_agent = "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0";
  
      // Intialize cURL
      $ch = curl_init();
      // Url to use
      curl_setopt( $ch, CURLOPT_URL, $login_url );
      curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
      // Set the cookies for the login in a cookie file.
      curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie_file );
      // Set SSL to false
      curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
      // User agent
      curl_setopt( $ch, CURLOPT_USERAGENT, $http_agent );
      // Maximum time cURL will wait for get response. in seconds
      curl_setopt( $ch, CURLOPT_TIMEOUT, 60 );
      curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
      // Return or echo the execution
      curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
      // Set Http referer.
      curl_setopt( $ch, CURLOPT_REFERER, $login_url );
      // Post fields to the login url
      curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
      curl_setopt( $ch, CURLOPT_POST, 1);
      // Save the return in a variable
      $content = curl_exec ($ch);  
      /*
      ** if you need to visit another url, you can do it here.
      ** curl_setopt( $ch, CURLOPT_URL, 'a new url address or a file download url' );
      ** $content = curl_exec ($ch);
      */
      // Close the cURL.
      curl_close( $ch );  
      // You can echo or return the page data here.
      $cookie_path = 'xxxxx.com';
      $f = fopen ($cookie_file, 'ro');
  
      $name_array = array();
  
      while (!feof ($f))
      { 
      $line = fgets ($f);
      $parts = explode ("\t", $line);
      $name = $parts[5];
      $value = trim ($parts[6]);
  
      if (!in_array($name, $name_array)){
      setcookie ($name, str_replace('%7C','|',$value), 0, '/',$cookie_path);
      $name_array[] = $name;
      }
      }
  
      unlink ($cookie_file);
  
  }
  
  add_action('wp_login', 'drupal_authentication');
  </code></pre>