Need PHP code to force SSL

MaxPower

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

Code:
<%
   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();
	}
?>

Tim
 
Try this instead:

Code:
<?php
    if( $_SERVER['[b][COLOR="Blue"]SERVER_PORT[/COLOR][/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!
 
Back
Top