PHPackages                             mistralys/ssl-switcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. mistralys/ssl-switcher

ActiveLibrary[Security](/categories/security)

mistralys/ssl-switcher
======================

PHP class to enforce an SSL connection in a website.

1.0.0(5y ago)010[2 issues](https://github.com/Mistralys/ssl-switcher/issues)MITPHPPHP &gt;=5

Since Feb 20Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Mistralys/ssl-switcher)[ Packagist](https://packagist.org/packages/mistralys/ssl-switcher)[ RSS](/packages/mistralys-ssl-switcher/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

SSL Switcher
============

[](#ssl-switcher)

PHP class to enforce an SSL connection in a website.

Installation
------------

[](#installation)

Simply require the package in your `composer.json` file.

```
composer require "mistralys/ssl-switcher"

```

Quick start
-----------

[](#quick-start)

The simplest way to use the script is to use the static `autoSwitch()` method:

```
use Mistralys\SSLSwitcher;

SSLSwitcher::autoSwitch('https://domain.extension');
```

This will check if the current connection is SSL or not, and redirect to the target URL as needed. Otherwise, the script continues as usual.

NOTE: Any existing request parameters are appended to the target URL, to stay on the same page.

SSL switching conditions
------------------------

[](#ssl-switching-conditions)

The script will redirect to the https version of the website only if the following conditions are met:

1. The script is not run from the command line
2. The script is not running from localhost
3. SSL is not enabled

Using class methods
-------------------

[](#using-class-methods)

When instantiating the class, you get access to its methods - for example to run some checks in your application before doing the switch to https.

```
use Mistralys\SSLSwitcher;

$switcher = new SSLSwitcher('https://domain.extension');

// Is a switch to https required?
if($switcher->isSwitchRequired())
{
    // Do something before the redirect
}

// Redirect
$switcher->switch();
```

Utility methods
---------------

[](#utility-methods)

The class has a few utility methods that can come in handy.

- `isCLI()` - Is the script running from the command line?
- `isLocalhost()` - Is the server run as localhost / 127.0.0.1?
- `isSSLActive()` - Is SSL enabled?
- `getTargetURL()` - The URL the script would redirect to.

Disabling the exit call
-----------------------

[](#disabling-the-exit-call)

By default, the class will call `exit()` after the redirect. If your application needs to handle this instead, the exit can be turned off:

```
use Mistralys\SSLSwitcher;

$switcher = new SSLSwitcher('https://domain.extension');
$switcher->setExitEnabled(false);
$switcher->switch();

// Handle the exit in the script instead
if($switcher->isSwitchRequired())
{
    exit();
}
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

1905d ago

Major Versions

0.1.1 → 1.0.02021-02-20

PHP version history (2 changes)0.1.0PHP &lt;=7.4.9

1.0.0PHP &gt;=5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8895528?v=4)[Mistralys](/maintainers/Mistralys)[@Mistralys](https://github.com/Mistralys)

---

Top Contributors

[![Mistralys](https://avatars.githubusercontent.com/u/8895528?v=4)](https://github.com/Mistralys "Mistralys (13 commits)")

### Embed Badge

![Health badge](/badges/mistralys-ssl-switcher/health.svg)

```
[![Health](https://phpackages.com/badges/mistralys-ssl-switcher/health.svg)](https://phpackages.com/packages/mistralys-ssl-switcher)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M212](/packages/defuse-php-encryption)[roave/security-advisories

Prevents installation of composer packages with known security vulnerabilities: no API, simply require it

2.9k97.3M6.4k](/packages/roave-security-advisories)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.7M112](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41278.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

86917.5M63](/packages/bjeavons-zxcvbn-php)[enlightn/security-checker

A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

33732.2M110](/packages/enlightn-security-checker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
