Получить сертификат SSL. После того, как HTTPS работает на вашем сервере (обратитесь к хостинговой компании, чтобы он заработал), вы можете использовать код, подобный следующему, для установки HTTPS-соединения в PHP. .htaccess - это еще один вариант, упомянутый в другом месте.
<?
function current_protocol()
{
$protocol = 'http';
if ( array_key_exists( 'HTTPS', $_SERVER ) && $_SERVER['HTTPS'] === 'on' )
{
$protocol = 'https';
}
return $protocol;
}
//------------------------------------------------------------------------
function current_has_ssl()
{
return current_protocol() == 'https';
}
//------------------------------------------------------------------------
function force_https()
{
if ( current_has_ssl() == false )
{
header( "HTTP/1.1 301 Moved Permanently" );
header( 'Location: https://example.com' );
exit();
}
}
//------------------------------------------------------------------------
// Usage:
force_https(); // at the top of a script before any output.