[hatena」ログインキーは変わります

 どうやら変わる時と変わらないときがある模様。
 ということで、phpでrk値を取得するスクリプト。エラーチェックはしていない。

<?php
error_reporting(E_ALL);

function get_rk($account,$password){

$data=http_build_query(array("name" => $account, "password" => $password,"persistent"   =>  "0",),'', '&');

$context = stream_context_create(array(
    'http' => array(
        'method'  => 'POST',
        'header'  => implode("\r\n", array(
            'Content-Type: application/x-www-form-urlencoded',
            'Content-Length: ' . strlen($data)
        )),
        'content' => $data
        )
));

$output = file_get_contents('http://www.hatena.ne.jp/login', false, $context);

foreach($http_response_header as $header){
    if(preg_match("/Set-Cookie: rk=(\w+); /",$header,$temp)>0){
        return $temp[1];
    }
}
}
?>

 例によってネタ元はこの人力検索
【PHP】【mixi】 PHPを使って、mixiのとあるページ(ユーザから指定される)に対して、file_get_contentsを行いたいのですが、何かいい方法はないでしょうか? mixiの場合.. - 人力検索はてな