How can PHP be used to check if a web server supports SSL/HTTPS connections?
To check if a web server supports SSL/HTTPS connections, you can use PHP's `stream_socket_client` function to attempt to establish an SSL connection with the server. If the connection is successful, it means that the server supports SSL/HTTPS.
$context = stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
]
]);
$fp = stream_socket_client('ssl://example.com:443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if ($fp) {
echo 'SSL/HTTPS connection is supported';
fclose($fp);
} else {
echo 'SSL/HTTPS connection is not supported';
}
Keywords
Related Questions
- What is the best way to check if entries exist in a MySQL database table using PHP?
- What steps can be taken to educate PHP beginners about the importance of prioritizing security measures in their code development process?
- Are there any built-in PHP functions that can simplify date manipulation tasks?