Need PHP code to force SSL

I’ve been using the following code on each ASP page I want to secure with SSL. I need the PHP equivalent. Thanks.

<% If Request.ServerVariables("SERVER_PORT")=80 Then Dim strSecureURL strSecureURL = "https://" strSecureURL = strSecureURL & Request.ServerVariables("SERVER_NAME") strSecureURL = strSecureURL & Request.ServerVariables("URL") Response.Redirect strSecureURL End If %>

Try this:

[PHP]<?php if( $_SERVER['REMOTE_PORT'] == 80) { header('Location:https://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/'.basename($_SERVER['PHP_SELF'])); die(); } ?>
[/PHP]

Tim

I placed the code in the web page but it doesn’t change it to https. I tried placing the code before the head tag, in the head tag and in the body.

Here’s a link to the page: http://www.kcsdreambox.com/test.php

Let me know if you have other suggestions.

Thanks for your help!

Try this instead:

<?php if( $_SERVER['[b][COLOR="Blue"]SERVER_PORT[/b]'] == 80) { ...

Tim

Bingo! That works. The code must be placed before the DOCTYPE HTML tag or an error is generated. In other words, the code should be the first thing on the page.

Thanks for your excellent help!