#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Posts
    2,568
    Rep Power
    171

    Force https with php


    Hi, I want users to see https instead of http for every page oon the site.

    Can I do this?
    PHP Code:
    if($_SERVER["HTTPS"] != "on")
    {
        
    header("Location: https://" $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
        exit();

    If not, what can I do?

    Thanks
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,745
    Rep Power
    9397
    It looks right. Try it.

    Even better than doing it in PHP would be doing it in your web server: virtualhost configuration or .htaccess.
    Code:
    RewriteEngine on
    RewriteCond %{HTTPS} off
    RewriteRule https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

IMN logo majestic logo threadwatch logo seochat tools logo