Https vs http - PHP Site URL Protokolü alın

0 Cevap php

Ben geçerli site url protokolünü kurmak için küçük bir fonksiyon yazdım ama SSL yok ve https altında çalışıp çalışmadığını test etmek nasıl bilmiyorum. Can you tell me if this is correct?

function siteURL()
{
    $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
    $domainName = $_SERVER['HTTP_HOST'].'/';
    return $protocol.$domainName;
}
define( 'SITE_URL', siteURL() );

Is it necessary to do it like above or can I just do it like?:

function siteURL()
{
    $protocol = 'http://';
    $domainName = $_SERVER['HTTP_HOST'].'/'
    return $protocol.$domainName;
}
define( 'SITE_URL', siteURL() );

Çapa etiket url http kullanıyor olsa bile SSL altında, sunucu otomatik olarak https url dönüştürmek değil mi? Bu protokol kontrol etmek için gerekli midir?

Teşekkür ederiz!

0 Cevap