url_is_accessable_via_ssl

Definition:
function url_is_accessable_via_ssl($url)

Determines if the blog can be accessed over SSL.
Determines if blog can be accessed over SSL by using cURL to access the site using the https in the siteurl. Requires cURL extension to work correctly.

Parameters

  • string $url

Return values

returns:Whether SSL access is available

Source code

function url_is_accessable_via_ssl($url)

{

	if (in_array('curl', get_loaded_extensions())) {

		$ssl = preg_replace( '/^http:\/\//', 'https://',  $url );



		$ch = curl_init();

		curl_setopt($ch, CURLOPT_URL, $ssl);

		curl_setopt($ch, CURLOPT_FAILONERROR, true);

		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);



		curl_exec($ch);



		$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

		curl_close ($ch);



		if ($status == 200 || $status == 401) {

			return true;

		}

	}

	return false;

}

3267

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: