How to detect SSL traffic on the Kinamo shared hosting platform

Last updated on 06 Sep 2023, 13:16:49.
Category: All about SSL certificates | SSL technical

PHP SSL

The Kinamo web hosting platform allows you to use several types of SSL certificates.

The shared web hosting platform uses load balancers to spread the server requests on several webserver nodes (this to obtain a higher degree of redundancy and to ensure a stable PHP hosting platform).

Using SSL certificates on the Kinamo shared hosting platform

On the Kinamo shared hosting platform, certificates are installed on the load balancers and traffic is being SSL offloaded to webserver nodes underneath.
What is the impact for you as a developer: the connections on the website will always be standard HTTP traffic (in other words everything arrives at port 80 and is not encrypted) since the load balancers have the task of decrypting traffic (hence the name "SSL offloading").

How to detect whether a visitor arrived through HTTPS or not?

Often, an application requires you to check whether the visitor arrived through HTTPS on the website, and if this was not the case the visitor has to be redirected to the HTTPS website. On a standard webserver this imposes no problem and it can be achieved with simple PHP code by detecting whether the port on which the visitor arrived was port 80 (normal HTTP traffic) or port 443 (HTTPS traffic), or if the protocol being used was HTTP or HTTPS. On the Kinamo shared hosting platform this will not work because of the reason explained above (SSL offloading).
To solve this problem we have added two addiitonal headers. Based on these headers you may check whether the visitor arrived through HTTPS or not:

$_SERVER["HTTP_X_FORWARDED_PORT"]

This header will tell you the port on which the visitor arrived: in case of HTTPS it is 443, in case of normal HTTP traffic it is 80.

$_SERVER["HTTP_X_FORWARDED_PROTO"]

This header gives you the protocol on which the visitor traffic arrived, HTTPS or HTTP.

PHP HTTPS header detection

The simple example below shows you how you may detect by port or protocol whether someone arrived the correct way, if this is not the case, the visitor will be redirected to the correct URL.Attention, this code ONLY works on the Kinamo hosting platform! For standard PHP, other server headers are used!
if ($_SERVER['HTTP_X_FORWARDED_PORT'] != 443 || $_SERVER['HTTP_X_FORWARDED_PROTO'] != 'https')
{
 $redirect = "Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 header( $redirect, true, 301 );
 exit(0);
}

Set up Wordpress for HTTPS

Wordpress requires some adjustments to correctly detect HTTPS traffic. For this we would like to refer you to the FAQ item about Wordpress and HTTPS traffic detection.

Happy coding!


Related articles

Kinamo mail server settings (mail server cheat sheet)

The following article provides the basic settings and server names (domain names) for the Kinamo mail infrastructure. These settings allow...

Read more

Create an automatic SPAM filter in the Kinamo Webmail

This article explains how you may create a filter that will automatically place SPAM messages in a special folder, so...

Read more

Order an SSL certificate? What is an SSL certificate?

You need to order an SSL certificate? But what is an SSL certificate? And why is everyone saying that it...

Read more

Need extra help?

Were not all your questions answered?
Don't worry, we will be happy to help you via a support request!

Select your language

All languages: