{"id":15042289,"url":"https://github.com/yii2tech/https","last_synced_at":"2025-10-04T05:31:27.994Z","repository":{"id":57087036,"uuid":"59121180","full_name":"yii2tech/https","owner":"yii2tech","description":"Secure connection (https) handling","archived":true,"fork":false,"pushed_at":"2019-07-03T11:42:49.000Z","size":21,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-09-07T09:02:03.003Z","etag":null,"topics":["http","https","yii","yii2","yii2-extension"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yii2tech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["klimov-paul"],"patreon":"klimov_paul"}},"created_at":"2016-05-18T14:05:59.000Z","updated_at":"2023-10-07T00:42:11.000Z","dependencies_parsed_at":"2022-08-25T00:50:47.574Z","dependency_job_id":null,"html_url":"https://github.com/yii2tech/https","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/yii2tech/https","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yii2tech%2Fhttps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yii2tech%2Fhttps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yii2tech%2Fhttps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yii2tech%2Fhttps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yii2tech","download_url":"https://codeload.github.com/yii2tech/https/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yii2tech%2Fhttps/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278267463,"owners_count":25958869,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","https","yii","yii2","yii2-extension"],"created_at":"2024-09-24T20:47:05.535Z","updated_at":"2025-10-04T05:31:27.643Z","avatar_url":"https://github.com/yii2tech.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yii2tech\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://avatars2.githubusercontent.com/u/12951949\" height=\"100px\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eSecure connection (https) handling extension for Yii2\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\nThis extension provides some tools for the secure connection (https) handling.\n\nFor license information check the [LICENSE](LICENSE.md)-file.\n\n[![Latest Stable Version](https://poser.pugx.org/yii2tech/https/v/stable.png)](https://packagist.org/packages/yii2tech/https)\n[![Total Downloads](https://poser.pugx.org/yii2tech/https/downloads.png)](https://packagist.org/packages/yii2tech/https)\n[![Build Status](https://travis-ci.org/yii2tech/https.svg?branch=master)](https://travis-ci.org/yii2tech/https)\n\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require --prefer-dist yii2tech/https\n```\n\nor add\n\n```json\n\"yii2tech/https\": \"*\"\n```\n\nto the require section of your composer.json.\n\n\nUsage\n-----\n\nThis extension provides some tools for the secure connection (https) handling.\n\nFilter [[\\yii2tech\\https\\SecureConnectionFilter]] allows automatic redirection from 'http' to 'https' protocol,\ndepending of which one is required by particular action. Actions separation into those requiring secure protocol\nand the ones requiring unsecure protocol can be setup via `secureOnly` and `secureExcept` properties.\n\nBeing descendant of [[yii\\base\\ActionFilter]], [[\\yii2tech\\https\\SecureConnectionFilter]] can be setup both at the\ncontroller level and at module (application) level.\n\nApplication configuration example:\n\n```php\nreturn [\n    'as https' =\u003e [\n        'class' =\u003e 'yii2tech\\https\\SecureConnectionFilter',\n        'secureOnly' =\u003e [\n            'site/login',\n            'site/signup',\n        ],\n    ],\n    // ...\n];\n```\n\nController configuration example:\n\n```php\nuse yii\\web\\Controller;\nuse yii2tech\\https\\SecureConnectionFilter;\n\nclass SiteController extends Controller\n{\n    public function behaviors()\n    {\n        return [\n            'https' =\u003e [\n                'class' =\u003e SecureConnectionFilter::className(),\n                'secureOnly' =\u003e [\n                    'login',\n                    'signup',\n                ],\n            ],\n        ];\n    }\n\n    // ...\n}\n```\n\n**Heads up!** Do not forget about `only` and `except` properties of the filter. Keep in mind that `secureOnly`\nand `secureExcept` can not affect those actions, which are excluded from filtering via `only` and `except`.\nYou may use this to skip some actions from the secure connection processing.\n\n**Heads up!** Be aware of the forms, which may appear at on protocol but require submission to the other.\nRequest body can not be transferred during redirect, so submitted data will be lost. You'll have to setup\nform action manually with the correct schema, instead of relying on the filter.\n\n\n## Automatic URL creation \u003cspan id=\"automatic-url-creation\"\u003e\u003c/span\u003e\n\nUsing simple redirect from one protocol to another is not efficient and have a risk of loosing data submitted via\nweb form. Thus it is better to explicitly specify URL with correct protocol in your views.\nYou may simplify this process using [[\\yii2tech\\https\\SecureUrlRuleFilter]] action filter. Once applied it will adjust\n[[\\yii\\web\\UrlManager::rules]] in the way [[\\yii\\web\\UrlManager::createUrl()]] method will automatically create\nabsolute URL with correct protocol in case it miss matches current one.\n\nApplication configuration example:\n\n```php\nreturn [\n    'as secureUrlRules' =\u003e [\n        'class' =\u003e 'yii2tech\\https\\SecureUrlRuleFilter',\n        'secureOnlyRoutes' =\u003e [\n            'auth/login',\n            'site/signup',\n        ],\n        'secureExceptRoutes' =\u003e [\n            'site/index',\n            'help/\u003caction\u003e',\n        ],\n    ],\n    'components' =\u003e [\n        'urlManager' =\u003e [\n            'enablePrettyUrl' =\u003e true,\n            'showScriptName' =\u003e false,\n            'rules' =\u003e [\n                '/' =\u003e 'site/index',\n                'login' =\u003e 'auth/login',\n                'signup' =\u003e 'site/signup',\n                '\u003caction:contact|faq\u003e' =\u003e 'help/\u003caction\u003e',\n            ]\n        ],\n    ],\n    // ...\n];\n```\n\nNow [[\\yii\\web\\UrlManager::createUrl()]] will create URLs with correct protocol without extra efforts:\n\n```php\nif (Yii::$app-\u003erequest-\u003eisSecureConnection) {\n    echo Yii::$app-\u003eurlManager-\u003ecreateUrl(['site/index']); // outputs: 'http://domain.com/'\n    echo Yii::$app-\u003eurlManager-\u003ecreateUrl(['auth/login']); // outputs: '/login'\n} else {\n    echo Yii::$app-\u003eurlManager-\u003ecreateUrl(['site/index']); // outputs: '/'\n    echo Yii::$app-\u003eurlManager-\u003ecreateUrl(['auth/login']); // outputs: 'https://domain.com/login'\n}\n```\n\n\u003e Note: [[\\yii2tech\\https\\SecureUrlRuleFilter]] filter will take affect only if\n  [[\\yii\\web\\UrlManager::enablePrettyUrl]] is enabled.\n\n**Heads up!** once applied [[\\yii2tech\\https\\SecureUrlRuleFilter]] filter changes the state of related\n[[\\yii\\web\\UrlManager]] instance, which may make unexpected side effects. For example: this may\nbreak such features as parsing URL.\n\nThe more reliable way for automatic URL creation is usage of [[\\yii2tech\\https\\SecureConnectionUrlManagerTrait]].\nBeing used with the descendant of the [[\\yii\\web\\UrlManager]] it will adjust `createUrl()` method so it will behave\nexactly the same as in example above.\n\nTrait usage example:\n\n```php\nnamespace app\\components\\web;\n\nuse yii2tech\\https\\SecureConnectionUrlManagerTrait;\n\nclass MyUrlManager extends \\yii\\web\\UrlManager\n{\n    use SecureConnectionUrlManagerTrait;\n}\n```\n\nApplication configuration example:\n\n```php\nreturn [\n    'components' =\u003e [\n        'urlManager' =\u003e [\n            'class' =\u003e 'app\\components\\web\\MyUrlManager',\n            'enablePrettyUrl' =\u003e true,\n            'showScriptName' =\u003e false,\n            'rules' =\u003e [\n                '/' =\u003e 'site/index',\n                'login' =\u003e 'auth/login',\n                'signup' =\u003e 'site/signup',\n                '\u003caction:contact|faq\u003e' =\u003e 'help/\u003caction\u003e',\n            ],\n            'secureOnlyRoutes' =\u003e [\n                'site/signup',\n                'auth/*',\n            ],\n            'secureExceptRoutes' =\u003e [\n                'site/index',\n                'help/*',\n            ],\n        ],\n    ],\n    // ...\n];\n```\n\nIn case you do not use any custom URL manager in your project you can use [[\\yii2tech\\https\\UrlManager]], which already\nhave [[\\yii2tech\\https\\SecureConnectionUrlManagerTrait]] applied.\n\n\u003e Note: usage of [[\\yii2tech\\https\\SecureConnectionUrlManagerTrait]] is more reliable then [[\\yii2tech\\https\\SecureUrlRuleFilter]],\n  but it may consume more computing resources at some cases. Still it is recommended to use trait instead of filter.\n\n\u003e Note: [[\\yii2tech\\https\\SecureConnectionUrlManagerTrait]] and [[\\yii2tech\\https\\SecureUrlRuleFilter]] process routes\n  in the different way: filter uses those defined by URL rules, while trait operates exact route names as they passed\n  to `createUrl()` method.\n","funding_links":["https://github.com/sponsors/klimov-paul","https://patreon.com/klimov_paul"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyii2tech%2Fhttps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyii2tech%2Fhttps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyii2tech%2Fhttps/lists"}