fork download
  1. class HSTS{
  2.  
  3. public static $maxAge = 31536000;
  4.  
  5. /**
  6.   * Enables HSTS.
  7.   */
  8. public static function enable() {
  9. if (Detector::getHttps() === true) {
  10. header('Strict-Transport-Security: max-age='.self::$maxAge);
  11. } else {
  12. $httpsURL = 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  13. if( count( $_POST )>0 )
  14. die( 'Page should be accessed with HTTPS, but a POST Submission has been sent here. Adjust the form to point to '.$httpsURL );
  15. if( !isset( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS']!=='on'){
  16. if( !headers_sent() ){
  17. header( "Status: 301 Moved Permanently" );
  18. header( "Location: $httpsURL" );
  19. exit();
  20. }else{
  21. die( '<script type="javascript">document.location.href="'.$httpsURL.'";</script>' );
  22. }
  23. }
  24. }
  25. }
  26. }
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
class HSTS{

        public static $maxAge = 31536000;

        /**
         * Enables HSTS.
         */
        public static function enable() {
            if (Detector::getHttps() === true) {
                header('Strict-Transport-Security: max-age='.self::$maxAge);
            } else {
                $httpsURL = 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
                if( count( $_POST )>0 )
                    die( 'Page should be accessed with HTTPS, but a POST Submission has been sent here. Adjust the form to point to '.$httpsURL );
                if( !isset( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS']!=='on'){
                    if( !headers_sent() ){
                        header( "Status: 301 Moved Permanently" );
                        header( "Location: $httpsURL" );
                        exit();
                    }else{
                        die( '<script type="javascript">document.location.href="'.$httpsURL.'";</script>' );
                    }
                }
            }
        }
    }