GlowHost Web Hosting Forums  

Go Back   GlowHost Web Hosting Forums > In The Lounge > Programming Talk
Register Forum FAQ Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-12-2008
charlesh's Avatar
Master Glow Jedi
 
Join Date: Aug 2006
Location: Wichita, Kansas - better than you imagined it would be.
Posts: 152
Rep Power: 37
charlesh is on a distinguished road
Default Force https

If you're running ssl and don't want a user to get to a page unsecured, i've created this function to force https based on URI. If you put it in an include file and then run the function at the top of your script, it will redirect back to the page with https invoked.

For those pages that don't require https, to minimize server load, i've created the oppposite function. Let me know how it works out if you use it:

PHP Code:
function forcehttps(){
  if (!isset(
$_SERVER['HTTPS']))
 
  {
   
$ref $_SERVER['REQUEST_URI'];
   
header("Location:https://wwww.yoursite.com".$ref);
   exit;
 
  }
}
function 
killhttps(){
  if (isset(
$_SERVER['HTTPS']))
 
  {
   
$ref $_SERVER['REQUEST_URI'];
   
header("Location:http://wwww.yoursite.com".$ref);
   exit;
 
  }

__________________
Charles H
http://www.harmonmediagroup.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-12-2008
sergey's Avatar
Newbie
 
Join Date: Aug 2005
Posts: 181
Rep Power: 51
sergey is on a distinguished road
Default

Thanks for sharing it with us Charles. You can also redirect non-secure urls to secure links by adding one of the following directives to .htaccess file:

Code:
 RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
or

Code:
 RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[How To] Redirect from HTTP to HTTPS using mod_rewrite sergey Knowledge Base 1 05-13-2008 02:21 PM


All times are GMT -5. The time now is 07:05 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO
Copyright 2000-2007 GlowHost.com