lunes, 20 de abril de 2009

Redirigir de http a https desde PHP

Este código sirve para redireccionar a la gente que entre a nuestro sitio web por http en lugar de https

<?php

if(!$_SERVER['HTTPS']== 'on'){

$url_https="https://". $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

header("Location: $url_https");

exit();

}

?>

3 comentarios:

  1. gracias me fue de gran ayuda

    ResponderEliminar
  2. Para el causar el efecto contrario:

    if($_SERVER['HTTPS']== 'on'){
    $url_http="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    header("Location: $url_http");
    exit(); }

    ResponderEliminar
  3. donde pongo este codigo?

    ResponderEliminar