PHP|file_get_contents()を使う時にユーザエージェントを設定する
スポンサーリンク
file_get_contents()を使う時にユーザエージェントを設定する
stream_context_create()を使って、コンテキストを生成したのちに、file_get_contents()に渡すことでユーザーエージェントをセットできます。
$options = array( 'http' => array( 'method' => 'GET', 'header' => 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Tablet PC 2.0)', ), ); // コンテキスト生成 $context = stream_context_create($options); // コンテンツ取得 $html = file_get_contents('http://ドメイン指定/', false, $context);
更新日:2018年10月26日
作成日:2018年10月26日