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

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,995
    Rep Power
    173

    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. Confusing Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    15,874
    Rep Power
    9569
    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