0

I have this code :

    function getCert($domain)
{
    $g    = stream_context_create(array("ssl" => array("capture_peer_cert" => true)));
    $r    = stream_socket_client("ssl://{$domain}:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $g);
    $cont = stream_context_get_params($r);
    return openssl_x509_parse($cont["options"]["ssl"]["peer_certificate"]);
}

This code works fine with php 7.4 and return the result that I need but when I change the php version to 8.0 returns false without failure

adnen manssouri
  • 51
  • 2
  • 11
  • Have you tried dumping the contents of `$cont` to see if the information is there under a different key? – IMSoP Jul 07 '21 at 14:05
  • this is the error message `Fatal error: Uncaught TypeError: stream_context_get_params(): Argument #1 ($context) must be of type resource, bool given` – adnen manssouri Jul 07 '21 at 14:20
  • You can read this documentation to know what I mean [link](https://www.php.net/manual/en/function.stream-socket-client.php) _italic_ **bold** – adnen manssouri Jul 07 '21 at 14:27
  • OK, so the 3rd and 4th lines you show are irrelevant, and the actual error is happening in `stream_socket_client`, which is returning false. – IMSoP Jul 07 '21 at 14:35
  • Following that link, did you read the "Errors/Exceptions" section? I see you're passing in $errno and $errstr, but not checking them anywhere. – IMSoP Jul 07 '21 at 15:04
  • I tried that a few minutes ago and this is the result `"Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?"` – adnen manssouri Jul 07 '21 at 15:14
  • In that case, it sounds like you need to check your configuration., as discussed in other questions which I found by searching that error message. Probably when you upgraded PHP it's using a different set of configuration files, or a different library location. – IMSoP Jul 07 '21 at 15:22
  • Yes I found th needed extensions Thank you for interesting – adnen manssouri Jul 07 '21 at 15:56
  • I added this two lines `extension_dir=ext` and `extension=php_openssl.dll` to php.ini file – adnen manssouri Jul 07 '21 at 15:59

0 Answers0