1

I've got a script that checks the current page for an SSL, but I need it to work so when a user enters a URL into a form and clicks the submit button it will bring back saying yes "the URL you have entered has SSL", or if it doesn't then bring back "this site doesn't have SSL".

Here's my PHP code:

if ( !empty( $_SERVER['HTTPS'] ) ) { echo "<p>This page does not have SSL. It would be worth adding SSL to this website as it's a ranking factor</p>"; }else{ echo '<p>Good job, this page has SSL.</p>'; }

Thanks in advance.

2
  • So you just want to check if the domain they entered begins with https ? Commented May 17, 2017 at 22:48
  • Exactly that, but it would be cool if it would check the HTTP server status for HTTPS or not. Commented May 17, 2017 at 22:52

1 Answer 1

1

It seems that you're allowing users to check their website, based on that, you can use:

$url = parse_url( 'https://user.url' ); if( $url['scheme'] == 'https' ) { echo '<p>Good job, this page has SSL.</p>'; }else{ echo "<p>This page does not have SSL. It would be worth adding SSL to this website as it's a ranking factor</p>"; } 

OLD ANSWER - DOESN'T APPLY TO THE OP'S ANSWER BUT CAN BE USEFUL TO CHECK IF THE CURRENT URL IS USING HTTPS:

if ( $_SERVER['REQUEST_SCHEME'] == "https" ) { echo '<p>Good job, this page has SSL.</p>'; }else{ echo "<p>This page does not have SSL. It would be worth adding SSL to this website as it's a ranking factor</p>"; } 

You can also use:

if ( isset($_SERVER['HTTPS']) && 'on' === $_SERVER['HTTPS'] ) { echo '<p>Good job, this page has SSL.</p>'; }else{ echo "<p>This page does not have SSL. It would be worth adding SSL to this website as it's a ranking factor</p>"; } 

The last option seems to be the safest way to determine https.

Sign up to request clarification or add additional context in comments.

1 Comment

Sure, thanks. But isn't the last one getting the HTTP/HTTPS status of the current page, and not the requested URL from the form? Cheers.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.