2009-04-30
ユーザエージェントやリファラをなるべく簡単に偽装
<?php $ua = 'UnkoBrowser/1.0'; $rf = 'http://www.google.co.jp/'; //--- php.ini の user_agent ディレクティブを利用 ini_set('user_agent', "{$ua}\r\nReferer: {$rf}"); $buf = file_get_contents('http://www.google.com/'); //--- ストリームコンテキストを利用 $buf = file_get_contents( 'http://www.google.com/', false, stream_context_create( array( 'http'=>array( 'method' => "POST", 'header' => "Content-type: application/x-www-form-urlencoded\r\n" . "User-Agent: {$ua}\r\n" . "Referer: {$rf}\r\n" , 'content'=> "hoge=111&fuga=222" ) ) ) );