How to Redirect HTTP page to HTTPS in PHP

Here you go!

<?
function secure_page()
{
if ( !isset($_SERVER[‘HTTPS’]) || strtolower($_SERVER[‘HTTPS’]) != ‘on’ )
{
header (‘Location: https://’.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’]);
exit();
}
}
secure_page();
?>

Just put that at the top of your code. I recommend using an include file so that you only have to load one include at the top of your code (keeps it nice and clean).

What you should do next . . .

1. For more articles like this, subscribe to our newsletter.
2. For a deep dive on a subject, listen to our Podcasts.
3. Schedule your FREE personalized call with our team. One of our friendly team members will provide an audit of your website / marketing and ideas for improvements.
Blog Decorative Background

Join the Sales and Marketing News, receive our last insights, tips and best practices.

Our 7 Guarantees

Keeping 2,000+ Clients Happy Since 2001.

1
You Will Love Your Design We design to please you and your clients
2
Same-Day Support 24-hour turnaround edits during business hours
3
Free Education We provide knowledge to help you expand
4
No Hidden Charges We quote flat-rate projects
5
Own Your Site No strings attached
6
We Create Results SEO, PPC, content + design = clients
7
We Make Life Easier One agency for web, branding and marketing