This code is checking the php server variable for https, this is a variable that should have a value if you are on https. The code checks to see if it is not set, if it is set but has no value, or if it is set to 'off'. If any of these three conditions are met then the page is not being served up through https. The action of this check is to send the user to this page via https.
You might be having a problem with the redirect value in the header. Rather than use the value in the code for this you should try setting the redirect like this:
header("Location: https://yoursite.com/yourpage.php");
Hard coding in the page might help it. If you would like to know more about this php setting here is the manual page that includes info for it:
reserved.variables.server.php
If the values are not like this on your server, or the code just does not work for your instance you may need to come up with a different method of sending the user to the https version of the page.