Page 1 of 1

Need PHP code to force SSL

Posted: Fri Apr 21, 2006 12:38 am
by Maxed Out
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I've been using the following code to secure ASP pages with SSL. I'm looking for the PHP equivalent. I want to change an "http" address to "https" regardless of the page people enter the site on. Thanks.
[syntax="asp"]
<%
   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
%>

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Apr 21, 2006 12:41 am
by John Cartwright

Code: Select all

if ($_SERVER['HTTPS'] != 'on')
{
   //redirect to https://.. 
   header( ... )
}
as far as the server variables to determine the current, they can be viewed using

Code: Select all

echo '<pre>'; 
print_r($_SERVER);
echo '</pre>';