PHP检查是否有可能获得SSL

Well I do not own a wildcard SSL for my homepage, but I have a quite few subdomains that is included in my SSL Certificate, but I wanna see if there would be plausible to check if the subdomain has a valid ceritificate before redirecting to the subdomain in HTTPS.

Why do i want to know this? because I'm running all my domains through one php file, thats meant for DomainControll, that's including a database for what pages exists and such, but instead of having an extra row in the mysql weather not its awailable in HTTPS is kind-off waste, but if there isn't this would be the answer for my question. Hopefully there exists a way to do what i wish.

Thanks ~Martin

You can use curl to test. If CURLOPT_SSL_VERIFYPEER is set to true (the default), the result will be false.

<?php 
$ch = curl_init('https://www.example.org');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
$result = curl_exec($ch);
echo curl_error($ch);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
$result = curl_exec($ch);
echo curl_error($ch);