ラボ > PHP:ファイル関連

php エラーページのソースも取得(file_get_contents)

404や500のときのレスポンスボディを取得したかった

作成日:2019-06-07, 更新日:2019-06-07

基本

$context = stream_context_create();
stream_context_set_option($context, 'http', 'ignore_errors', true);

// ソース
$source = @file_get_contents($url, false, $context);

// ヘッダ情報(ステータスコードとかの確認)
var_dump($http_response_header);