What are the potential pitfalls when using fsockopen to make HTTPS requests?

When using fsockopen to make HTTPS requests, potential pitfalls include not verifying the server's SSL certificate, which can lead to security vulnerabilities. To solve this issue, you should verify the SSL certificate of the server you are connecting to by using stream_socket_enable_crypto with the "crypto_method" set to STREAM_CRYPTO_METHOD_TLS_CLIENT.

$host = 'www.example.com';
$port = 443;

$socket = fsockopen('ssl://' . $host, $port, $errno, $errstr, 30);
if (!$socket) {
    die("Error: $errstr ($errno)");
}

stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);

// Now you can send your HTTPS request using fwrite and read the response using fread

fclose($socket);