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.
About Peter Boyd
Lawyer, geek & father of twin girls and a boy, who chose the path of starting a web design & marketing company.
Category
Development
Join our newsletter, where you will learn educational info on latest insights, tips and best practices.
Share:
About Us
Did you know more than 200 clients have worked with PaperStreet for more than 10 years?
Get a Free Website
Analysis and Consultation
Marketing Services