Possible Duplicate:
Check if the url is contains the http or https
What is the code to figure out whether the given URL contains http://
or https://
at the beginning using PHP and regular expressions?
We can use RegEx (Regular Expressions) to check if http or https exists in the URL string. But there is another quick way as well. We can use indexOf() to to check for the same.
PHP – Check if String Starts with http To check if string starts with “http”, use PHP built-in function strpos(). strpos() takes the string and substring as arguments and returns 0, if the string starts with “http”, else not. This kind of check is useful when you want to verify if given string is an URL or not.
So, using the $_SERVER['HTTPS'] in isset() function, that is used to check whether it exists or not. This will also tell us whether HTTPS is enabled or not. Check the value of $_SERVER['HTTPS'], if it is “on”, then HTTPS is enabled and we have to append “https” to the URL.
They can both be open at the same time, they can even serve different websites. In some ways they are 2 different websites. To avoid this you can simply close down port 80, or alternatively, make sure that website served on port 80 always sends a redirect to the https website.
you can use parse_url
<?php
$url = parse_url('https://example.org');
if($url['scheme'] == 'https'){
// is https;
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With