Help! PHP won't redirect to HTTPS once SSL is actually applied to the site

This is probably really stupid but I can’t figure out why this isn’t working. So I have this code on my page.

[php]<?php
$https_url = ‘https://somesite.com’;
if ( isset( $_SERVER[‘HTTPS’] ) && $_SERVER[‘HTTPS’] == ‘off’ )
{
header('location: ’ . $https_url);
exit;
}
else if ( !isset( $_SERVER[‘HTTPS’]) && $_SERVER[‘SERVER_PORT’] == 443 )
{
header('location: ’ . $https_url);
exit;
}
?>[/php]
When I was just trying this code out it worked and redirected to https. However, once we actually applied the SSL to the page, the code stopped working and I get the error “The page must be viewed over a secure location.” It throws the error before it processes anything on that page. I found the code online and these HTTPS redirects work for everyone else, so how come on my site it won’t read the code before telling me I need to have a https:// url? Thanks for any insight!

I figured it out. Our server guy was requiring the encryption so it didn’t care what I had on a page. If the original URL wasn’t https it would complain. Once he just applied SSL to the page but unchecked the box requiring it, it started working.

dam server guys :stuck_out_tongue: ::slight_smile:

glad you got it fixed :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service