以下のようなコードで、Basic認証付きのページにfile_get_contentsをしてGETリクエストした際、0が返ってきます。
<?php $url = "https://hogehoge"; $basic = array( 'Authorization: Basic '.base64_encode('user:password'), ); $options = array( 'https' => array( 'ignore_errors' => true, 'method' => 'GET', 'header' => implode("\r\n", $basic ) ) ); $context = stream_context_create($options); $result = @file_get_contents($url, false, $context); $pattern = '#\AHTTP/\d+.\d+ (\d+) (.*)\E#'; preg_match($pattern, $http_response_header[0], $matches); $code = (int)$matches[1]; var_dump($code);
htmlソース自体、全く取得できませんでした。
この場合、どのような原因が考えられるでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/20 07:09
2018/02/20 08:36