Home > Backend Development > PHP Tutorial > Why Does My PHP Code Get an 'SSL Operation Failed with Code 1' Error, and How Can I Fix It?

Why Does My PHP Code Get an 'SSL Operation Failed with Code 1' Error, and How Can I Fix It?

Linda Hamilton
Release: 2024-12-21 02:02:09
Original
945 people have browsed it

Why Does My PHP Code Get an

SSL Operation Failed with Code 1

This PHP code snippet:

$response = file_get_contents("https://maps.co.weber.ut.us/arcgis/rest/services/SDE_composite_locator/GeocodeServer/findAddressCandidates?Street=&SingleLine=3042+N+1050+W&outFields=*&outSR=102100&searchExtent=&f=json");
Copy after login

encounters an error: "SSL operation failed with code 1." This issue is related to the upgrades in PHP 5.6 concerning OpenSSL.

Solution:

To resolve this issue, follow these steps:

  1. Navigate to the following documentation: http://php.net/manual/en/migration56.openssl.php
  2. As mentioned here, disable the "verify_peer" and "verify_peer_name" settings by passing them as arguments to stream_context_create.

Your modified code should look like this:

$arrContextOptions = array(
    "ssl" => array(
        "verify_peer" => false,
        "verify_peer_name" => false,
    ),
);

$response = file_get_contents("https://maps.co.weber.ut.us/arcgis/rest/services/SDE_composite_locator/GeocodeServer/findAddressCandidates?Street=&SingleLine=3042+N+1050+W&outFields=*&outSR=102100&searchExtent=&f=json", false, stream_context_create($arrContextOptions));
Copy after login

Security Implications:

It is important to note that disabling certificate verification has significant security implications. It potentially allows an attacker to use an invalid certificate for eavesdropping. Use this solution only if you thoroughly understand its ramifications and cannot configure your system securely.

The above is the detailed content of Why Does My PHP Code Get an 'SSL Operation Failed with Code 1' Error, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template