I would like for users to be able to enter their company website URL in their company setup dialog, but I need to validate that. Apart from the typical sanitization functions, I would like to check if the URL scheme is http:// or https:// without the assumption the user has already entered it.
My function already parses the entered url to detect the scheme with a regex, but I would like to (ideally) check the URL from the server ala file_get_contents or parse_url and get the scheme, but I don’t know how could I do it.
Take a look at
parse_url(). The scheme will be returned in theschemeelement of the array.Edit 1
If the scheme is not present in the URL, then the
schemeelement will be missing.Edit 2
As @BenediktOlek says, you can use cURL to query the server:
If the server requires an HTTPS connection, and is correctly configured, then it should return a
Location:header with an HTTPS URL.