0

When I use file_get_contents with SSL and Proxy I have the following errors:

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:ssl3_get_record:wrong version number in D:\XAMPP\htdocs\instahu\app\vendor\classes\instagram.php on line 154

Warning: file_get_contents(https://www.instagram.com/explore/tags/test/): failed to open stream: Cannot connect to HTTPS server through proxy in D:\XAMPP\htdocs\instahu\app\vendor\classes\instagram.php on line 154

protected function curl_send($url,$post = null,$headers = null) {
  
    global $settings;
    global $language;
    global $lng;
    global $currentUrl;

    $file = file_get_contents("http://" . $_SERVER['HTTP_HOST'] . "/app/vendor/classes/proxy.txt");

    $file = explode("", $file);
    if (count($file) == 0) {
        
        include_once __DIR__.'/../../templates/500.php';
        exit();
    }
    
    $mysqli = new mysqli($settings['db']['host'],
                     $settings['db']['user'],
                     $settings['db']['pass'],
                     $settings['db']['name']);
    $exe_proxies = $mysqli->query('SELECT * FROM `proxy_used`');
    $proxies = [];
    while ($row = $exe_proxies->fetch_assoc()) {
        $proxies[] = $row['proxy'];
    }
    foreach ($file as $proxy) {
        if (!in_array($proxy, $proxies)) {
            $target_proxy = $proxy;
            break;
        }
    }
    
    if (!isset($target_proxy)) {
        $mysqli->query('DELETE FROM `proxy_used`');
        $target_proxy = $file[0];
    }
    $mysqli->query('INSERT INTO `proxy_used` SET `proxy` = "' . $target_proxy . '"');
    $target_proxy = 'tcp://'.$target_proxy;
    $mysqli->close();
    $headers['user-agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36';
    
    if ($headers) {
        foreach ($headers as $key => $header) {
            $result[] = $key . ":" . $header;
        }
        $headers = join("\r\n", $result);
    }
   
    $aContext = [
      'http' => [
        'proxy' => $proxy,
        'request_fulluri' => true,
        //'method' => $post ? 'POST' : 'GET',
        //'content' => http_build_query($post),
        'header' => $headers,
      ],
    ];

    $cxContext = stream_context_create($aContext);
   
    $server_output = file_get_contents($url, False, $cxContext);
    preg_match('#\d{3}#', $http_response_header[0], $code);

    //var_dump($server_output, $code[0], $aContext, $url); exit();

    return ['server_output' => $server_output, 'httpcode' => $code[0]];
}
Community
  • 1
  • 1
  • 1
    Possible duplicate of [file\_get\_contents(): SSL operation failed with code 1. And more](https://stackoverflow.com/questions/26148701/file-get-contents-ssl-operation-failed-with-code-1-and-more) – Loek Aug 24 '18 at 08:53

1 Answers1

0

Sorry guys, I found a solution in my case, all what i change it's change key 'http' to 'https' in $aContext array and it's work