title: CURL & PHP SSLv3 Error and Can't Get TLS to Work
body: <p>I am trying to connect to PayPal sandbox using CURL.  I've searched both this website and many others trying to find the right answer however, none, and I mean none, have worked for me and I still get the error:</p>
  
  <blockquote>
    <p>SetExpressCheckout failed: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure ( 35 )</p>
  </blockquote>
  
  <p>I have the following CURL and PHP installed (It is bought and shared hosting so I cannot upgrade anything).</p>
  
  <ul>
  <li><strong>Curl Verison:</strong>  7.36.0</li>
  <li><strong>SSL Version:</strong> OpenSSL/0.9.8b </li>
  <li><strong>PHP Version:</strong> 5.4.45</li>
  </ul>
  
  <p>The code I am currently using:</p>
  
  <pre><code>class MyPayPal {
      function PPHttpPost($methodName_, $nvpStr_, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode) {
          // Set up your API credentials, PayPal end point, and API version.
          $API_UserName = urlencode($PayPalApiUsername);
          $API_Password = urlencode($PayPalApiPassword);
          $API_Signature = urlencode($PayPalApiSignature);
  
          $paypalmode = ($PayPalMode=='sandbox') ? '.sandbox' : '';
  
          $API_Endpoint = "https://api-3t".$paypalmode.".paypal.com/nvp";
          $version = urlencode('109.0');
  
          // Set the curl parameters.
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_SSLVERSION, 4);
          curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
  
          curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
          curl_setopt($ch, CURLOPT_VERBOSE, 1);
  
          // Turn off the server and peer verification (TrustManager Concept).
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_POST, 1);
  
          // Set the API operation, version, and API signature in the request.
          $nvpreq = "METHOD=$methodName_&amp;VERSION=$version&amp;PWD=$API_Password&amp;USER=$API_UserName&amp;SIGNATURE=$API_Signature$nvpStr_";
  
          // Set the request as a POST FIELD for curl.
          curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
  
          // Get response from the server.
          $httpResponse = curl_exec($ch);
  
          if(!$httpResponse) {
              exit("&lt;span style='font-family: Verdana'&gt;&lt;strong&gt;$methodName_ failed: &lt;/strong&gt;".curl_error($ch).'&lt;strong&gt; (&lt;/strong&gt; '.curl_errno($ch).' &lt;strong&gt;)&lt;/strong&gt;&lt;/span&gt;');
          }
  
          // Extract the response details.
          $httpResponseAr = explode("&amp;", $httpResponse);
  
          $httpParsedResponseAr = array();
          foreach ($httpResponseAr as $i =&gt; $value) {
              $tmpAr = explode("=", $value);
              if(sizeof($tmpAr) &gt; 1) {
                  $httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
              }
          }
  
          if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
              exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
          }
  
      return $httpParsedResponseAr;
  }
  
  }
  </code></pre>
  
  <p>It doesn't matter what I do, I cannot seem to conquer this error. :(  Any guidance will be helpful.</p>