過去ログ取得用サンプルスクリプト

通称「●」でアクセス可能になる過去ログの取得をPHPで行う場合のサンプルです。
ライセンスはNYSL0.9982です。
[php]
<?php
/**
* 2ch.net Monazilla DOLIB Sample
*
* @version 1.0.0 yuhisa
*
* @license NYSL Version 0.9982
* http://www.kmonos.net/nysl/NYSL.TXT
*/

class OysterFry
{

private $SID;
const tora3 = "https://2chv.tora3.net/futen.cgi";
const userAgent = "OysterFry";

public function login ($MARUID, $MARUPW)
{

// クエリ作成
$data = "ID=".$MARUID."&PW=".$MARUPW;
// ヘッダーの作成
$header = array(
"Content-Type: application/x-www-form-urlencoded",
"User-Agent: DOLIB/1.00",
"X-2ch-UA: ".self::userAgent."/1.00",
"Content-Length: ".strlen($data)
);

// ストリームコンテキスト
$context = array(
"http" => array(
"method" => "POST",
"header" => implode("\r\n", $header),
"content" => $data."\n",
)
);

// 取得した SESSION-ID を保存
$this->SID = file_get_contents(self::tora3, false,
stream_context_create($context));
$this->SID = rtrim($this->SID);

if ($this->SID)
return true;

return false;

}

public function offlaw ($srv, $dir, $key)
{

// SESSION-ID から11文字以降を切り出し
$sid = substr($this->SID, 11);
// URL エンコード
$sid = urlencode($sid);
// リクエストに使用する User-Agent 切り取り
$rua = substr($sid, 0, (strpos($sid, ":"))-11);
// リクエスト先 URL
$offlaw = "http://{$srv}/test/offlaw.cgi/{$dir}/{$key}/?raw=0.0&sid=${sid}";

// ヘッダーの作成
$header = array(
"User-Agent: ".$rua." (".self::userAgent."/1.00)",
"Accept-Encoding: gzip, deflate",
);

// ストリームコンテキスト
$context = array(
"http" => array(
"method" => "GET",
"header" => implode("\r\n", $header),
)
);

// gzip 圧縮されているので zlib で読み込み
$rawdata = file_get_contents("compress.zlib://".$offlaw, false,
stream_context_create($context));

// エラーを投げる
if (substr($rawdata, 0, 4) == "-ERR") {
throw new Exception("An error occurred: received data or SID.");
exit;
}

// 生データ
if ($rawdata)
return $this->readOfflaw($rawdata);

return false;

}

private function readOfflaw ($rawdata)
{
return substr($rawdata, (strpos($rawdata, "\n")+1));
}

}

?>
[/php]

Last-modified: 2012年02月23日