LoginSignup
0
1

More than 3 years have passed since last update.

basic認証ありのサイトを偽装user agentでfile_get_contentsする

Posted at

headerにbasic認証用のAuthorizationと、User-Agentを追加するだけ(´▽`)

    $opts = array(
        'http' => [
            'method' => 'GET',
            'header' => implode("\r\n",[
                'Authorization: Basic ' . base64_encode('ID:PASS'),
                'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1',
            ]),
        ],
        'ssl' => [
            'verify_peer'      => false,
            'verify_peer_name' => false
        ]
    );

   file_get_contents($url, false, stream_context_create($opts));
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1