Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Below example, show how to make a call with customer custom HTTP_USER_AGENT

Code Block
function custom_file_get_contents( $url, $custom_http_user_agent="Mozilla/5.0 (CentOS; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36 (ck)")
{
        $options = array(
                'http'=>array( // it must be http, not https
                  'method'=>"GET",
                  'header'=>
                        "User-Agent: {$custom_http_user_agent}\r\n" .
                        "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\n" .
                        "Accept-Language: en-US\r\n" .
                        "Connection: keep-alive\r\n"
                )
        );
              
        $context = stream_context_create($options);
        $buff=@file_get_contents( $url, false, $context);
        return $buff;
}

echo custom_file_get_contents( "http://yahoo.com");
echo "\n\n"
echo custom_file_get_contents( "https://yahoo.com");

...