PHP Get Site URL Protocol - http vs https
It is not automatic. Your top function looks ok.
How do retrieve a URL protocol ( http or https )?
I can't figure out something smarter than assuming "http://" as default and, if it fails, try "https://"
if (!$html = file_get_html('http://' . $url)) $html = file_get_html('https://' . $url);
How to get the protocol in php?
$protocol = current(explode('/',$_SERVER['SERVER_PROTOCOL']));
If you really just want to know if it HTTPS is enabled or not, you can just use $_SERVER['HTTPS']
.
Identify whether the current url is http or https in a project
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
echo "something";
} else {
echo "something other";
}
notice the on
should be a string .
Is a protocol (eg. http or https) required for a URL to be valid?
They're both valid scheme-relative-URL strings, although they need to be in the context of a Base URL to be meaningful. When used within a web page, the web page will provide the Base URL context.
Although there are other, earlier standards for URLs, the whatwg document represents the most up-to-date, web compatible definition.
Related Topics
Import CSV File Directly into MySQL
Laravel Certificate Verification Errors When Sending Tls Email
Sanitizing Strings to Make Them Url and Filename Safe
Upgrading PHP in Xampp For Windows
How to Create Virtual Host on Xampp
In Where Shall I Use Isset() and !Empty()
How to Execute PHP That Is Stored in a MySQL Database
A Problem Occurred Somewhere in the Ssl/Tls Handshake
PHP Header Redirect Not Working
Pdo Prepared Statements With Wildcards
File_Get_Contents(): PHP_Network_Getaddresses: Getaddrinfo Failed: Name or Service Not Known
Resetting Array Pointer in Pdo Results
I Cannot Get My Login Form to Connect Interact Properly With MySQL Database