0

My website is https://www.mystylequest.com. We provide answers to fashion related questions like "can I find this dress in Yellow?". Answering a question involves submitting a link to a website with the dress, then my website scraps the neccessary images from the submitted link. However, we keep getting this error: file_get_contents(): SSL: Success upon submitting a valid image link (eg: https://poshmark.com/listing/Blue-and-White-Striped-Palazzo-Pants-5cf5ccaf6a7fbadddcaf2f07).

Here is the code:

if (isset($_POST['SubmitAnswersWithImage'])) {
    $image_url = trim($_POST['AnswerImg']);
    $url = trim($_POST['AnswerUrl']);
    $postId = (int)$_POST['PostId'];

    // This is to bypass websites that block our ip
    $aContext = array(
        'http' => array(
            'proxy' => 'tcp://138.68.161.60:8080',
            'request_fulluri' => true,
         ),
    );
    $cxContext = stream_context_create($aContext);
    $image_data = file_get_contents($image_url, false, $cxContext); // Error occurs
    $web_url = GoogleStorageManager::uploadBlob('quest_answers', $image_data)->webUrl();
<!-- irrelevant code -->

Any solutions will be greatly appreciated

Thanks in anticipation.

1 Answers1

0

try

// This is to bypass websites that block our ip
$aContext = array(
    'http' => array(
        'proxy' => 'tcp://138.68.161.60:8080',
        'request_fulluri' => true,
     ),
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
    ),
);

https://www.php.net/manual/en/migration56.openssl.php

An official document describing the changes made to open ssl in PHP 5.6 From here I learned of one more parameter I should have set to false: "verify_peer_name"=>false

Note: This has very significant security implications. Disabling verification potentially permits a MITM attacker to use an invalid certificate to eavesdrop on the requests. While it may be useful to do this in local development, other approaches should be used in production.

Mike Foxtech
  • 1,633
  • 1
  • 6
  • 7