PHPackages                             yii2tech/https - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. yii2tech/https

AbandonedArchivedYii2-extension[Utility &amp; Helpers](/categories/utility)

yii2tech/https
==============

Tools for the secure connection (https) handling

1.0.0(9y ago)122.1k3BSD-3-ClausePHP

Since Jul 12Pushed 7y ago1 watchersCompare

[ Source](https://github.com/yii2tech/https)[ Packagist](https://packagist.org/packages/yii2tech/https)[ RSS](/packages/yii2tech-https/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

 [ ![](https://avatars2.githubusercontent.com/u/12951949) ](https://github.com/yii2tech)

Secure connection (https) handling extension for Yii2
=====================================================

[](#secure-connection-https-handling-extension-for-yii2)

This extension provides some tools for the secure connection (https) handling.

For license information check the [LICENSE](LICENSE.md)-file.

[![Latest Stable Version](https://camo.githubusercontent.com/becc7d7a79a903b9cd6892d940232f78c5c44ad1dda1b174f90b38d41d567ca5/68747470733a2f2f706f7365722e707567782e6f72672f79696932746563682f68747470732f762f737461626c652e706e67)](https://packagist.org/packages/yii2tech/https)[![Total Downloads](https://camo.githubusercontent.com/1b0a443a4c85a43dd23964ce0ad6b7fab3ebe99235181ee224af0c9f270b1bb4/68747470733a2f2f706f7365722e707567782e6f72672f79696932746563682f68747470732f646f776e6c6f6164732e706e67)](https://packagist.org/packages/yii2tech/https)[![Build Status](https://camo.githubusercontent.com/f850d353a3bbd1ecfe6b057711ad0236eff558c5930463aaa2a66396500fc4f1/68747470733a2f2f7472617669732d63692e6f72672f79696932746563682f68747470732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yii2tech/https)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist yii2tech/https

```

or add

```
"yii2tech/https": "*"
```

to the require section of your composer.json.

Usage
-----

[](#usage)

This extension provides some tools for the secure connection (https) handling.

Filter \[\[\\yii2tech\\https\\SecureConnectionFilter\]\] allows automatic redirection from 'http' to 'https' protocol, depending of which one is required by particular action. Actions separation into those requiring secure protocol and the ones requiring unsecure protocol can be setup via `secureOnly` and `secureExcept` properties.

Being descendant of \[\[yii\\base\\ActionFilter\]\], \[\[\\yii2tech\\https\\SecureConnectionFilter\]\] can be setup both at the controller level and at module (application) level.

Application configuration example:

```
return [
    'as https' => [
        'class' => 'yii2tech\https\SecureConnectionFilter',
        'secureOnly' => [
            'site/login',
            'site/signup',
        ],
    ],
    // ...
];
```

Controller configuration example:

```
use yii\web\Controller;
use yii2tech\https\SecureConnectionFilter;

class SiteController extends Controller
{
    public function behaviors()
    {
        return [
            'https' => [
                'class' => SecureConnectionFilter::className(),
                'secureOnly' => [
                    'login',
                    'signup',
                ],
            ],
        ];
    }

    // ...
}
```

**Heads up!** Do not forget about `only` and `except` properties of the filter. Keep in mind that `secureOnly`and `secureExcept` can not affect those actions, which are excluded from filtering via `only` and `except`. You may use this to skip some actions from the secure connection processing.

**Heads up!** Be aware of the forms, which may appear at on protocol but require submission to the other. Request body can not be transferred during redirect, so submitted data will be lost. You'll have to setup form action manually with the correct schema, instead of relying on the filter.

Automatic URL creation
-----------------------

[](#automatic-url-creation-)

Using simple redirect from one protocol to another is not efficient and have a risk of loosing data submitted via web form. Thus it is better to explicitly specify URL with correct protocol in your views. You may simplify this process using \[\[\\yii2tech\\https\\SecureUrlRuleFilter\]\] action filter. Once applied it will adjust \[\[\\yii\\web\\UrlManager::rules\]\] in the way \[\[\\yii\\web\\UrlManager::createUrl()\]\] method will automatically create absolute URL with correct protocol in case it miss matches current one.

Application configuration example:

```
return [
    'as secureUrlRules' => [
        'class' => 'yii2tech\https\SecureUrlRuleFilter',
        'secureOnlyRoutes' => [
            'auth/login',
            'site/signup',
        ],
        'secureExceptRoutes' => [
            'site/index',
            'help/',
        ],
    ],
    'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '/' => 'site/index',
                'login' => 'auth/login',
                'signup' => 'site/signup',
                '' => 'help/',
            ]
        ],
    ],
    // ...
];
```

Now \[\[\\yii\\web\\UrlManager::createUrl()\]\] will create URLs with correct protocol without extra efforts:

```
if (Yii::$app->request->isSecureConnection) {
    echo Yii::$app->urlManager->createUrl(['site/index']); // outputs: 'http://domain.com/'
    echo Yii::$app->urlManager->createUrl(['auth/login']); // outputs: '/login'
} else {
    echo Yii::$app->urlManager->createUrl(['site/index']); // outputs: '/'
    echo Yii::$app->urlManager->createUrl(['auth/login']); // outputs: 'https://domain.com/login'
}
```

> Note: \[\[\\yii2tech\\https\\SecureUrlRuleFilter\]\] filter will take affect only if \[\[\\yii\\web\\UrlManager::enablePrettyUrl\]\] is enabled.

**Heads up!** once applied \[\[\\yii2tech\\https\\SecureUrlRuleFilter\]\] filter changes the state of related \[\[\\yii\\web\\UrlManager\]\] instance, which may make unexpected side effects. For example: this may break such features as parsing URL.

The more reliable way for automatic URL creation is usage of \[\[\\yii2tech\\https\\SecureConnectionUrlManagerTrait\]\]. Being used with the descendant of the \[\[\\yii\\web\\UrlManager\]\] it will adjust `createUrl()` method so it will behave exactly the same as in example above.

Trait usage example:

```
namespace app\components\web;

use yii2tech\https\SecureConnectionUrlManagerTrait;

class MyUrlManager extends \yii\web\UrlManager
{
    use SecureConnectionUrlManagerTrait;
}
```

Application configuration example:

```
return [
    'components' => [
        'urlManager' => [
            'class' => 'app\components\web\MyUrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '/' => 'site/index',
                'login' => 'auth/login',
                'signup' => 'site/signup',
                '' => 'help/',
            ],
            'secureOnlyRoutes' => [
                'site/signup',
                'auth/*',
            ],
            'secureExceptRoutes' => [
                'site/index',
                'help/*',
            ],
        ],
    ],
    // ...
];
```

In case you do not use any custom URL manager in your project you can use \[\[\\yii2tech\\https\\UrlManager\]\], which already have \[\[\\yii2tech\\https\\SecureConnectionUrlManagerTrait\]\] applied.

> Note: usage of \[\[\\yii2tech\\https\\SecureConnectionUrlManagerTrait\]\] is more reliable then \[\[\\yii2tech\\https\\SecureUrlRuleFilter\]\], but it may consume more computing resources at some cases. Still it is recommended to use trait instead of filter.

> Note: \[\[\\yii2tech\\https\\SecureConnectionUrlManagerTrait\]\] and \[\[\\yii2tech\\https\\SecureUrlRuleFilter\]\] process routes in the different way: filter uses those defined by URL rules, while trait operates exact route names as they passed to `createUrl()` method.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

Unknown

Total

1

Last Release

3644d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/854af1889dd7384243cff0bf0fde23463f76058b499b15c740f02e7033ec7ce6?d=identicon)[klimov-paul](/maintainers/klimov-paul)

---

Top Contributors

[![klimov-paul](https://avatars.githubusercontent.com/u/1482054?v=4)](https://github.com/klimov-paul "klimov-paul (19 commits)")

---

Tags

httphttpsyiiyii2yii2-extensionhttpssecureyii2secure connection

### Embed Badge

![Health badge](/badges/yii2tech-https/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[imanilchaudhari/yii2-currency-converter

This extension will help to find out current currency conversion rate.

2111.7k](/packages/imanilchaudhari-yii2-currency-converter)

PHPackages © 2026

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