forwarding all http to https

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

forwarding all http to https

Post by Luke »

This is kind of a stupid question, because I know how to do it I think, but how would you forward all traffic from http to https? (is there a better way than strpos?)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

strpos()? $_SERVER['HTTPS'] ;)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

so I want to make sure that the user is going to https://www.silversteepsecure.com (hot http://silversteepsecure.com or https://silversteepsecure.com or http://silversteepsecure.com). So would this be correct?

Code: Select all

if(empty($_SERVER['HTTPS']) || strpos(strtolower($_SERVER['HTTP_HOST']), "www") === false)
header('Location: https://www.silversteepsecure.com' . $_SERVER['REQUEST_URI']);
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

The Ninja Space Goat wrote:so I want to make sure that the user is going to https://www.silversteepsecure.com (hot http://silversteepsecure.com or https://silversteepsecure.com or http://silversteepsecure.com). So would this be correct?

Code: Select all

if(empty($_SERVER['HTTPS']) || strpos(strtolower($_SERVER['HTTP_HOST']), "www") === false)
header('Location: https://www.silversteepsecure.com' . $_SERVER['REQUEST_URI']);
try it yet?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

It works. No issues that I have found...
Post Reply