{"id":24540671,"url":"https://github.com/mistralys/ssl-switcher","last_synced_at":"2025-03-16T05:43:26.713Z","repository":{"id":57017607,"uuid":"340612134","full_name":"Mistralys/ssl-switcher","owner":"Mistralys","description":"PHP class to enforce using SSL on a website.","archived":false,"fork":false,"pushed_at":"2021-04-23T06:56:36.000Z","size":12,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-22T18:14:35.920Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mistralys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-20T09:17:23.000Z","updated_at":"2021-04-23T06:56:38.000Z","dependencies_parsed_at":"2022-08-22T11:31:22.151Z","dependency_job_id":null,"html_url":"https://github.com/Mistralys/ssl-switcher","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fssl-switcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fssl-switcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fssl-switcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mistralys%2Fssl-switcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mistralys","download_url":"https://codeload.github.com/Mistralys/ssl-switcher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830914,"owners_count":20354850,"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","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":[],"created_at":"2025-01-22T18:14:38.721Z","updated_at":"2025-03-16T05:43:26.689Z","avatar_url":"https://github.com/Mistralys.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SSL Switcher\n\nPHP class to enforce an SSL connection in a website.\n\n## Installation\n\nSimply require the package in your `composer.json` file.\n\n```\ncomposer require \"mistralys/ssl-switcher\"\n```\n\n## Quick start\n\nThe simplest way to use the script is to use the static `autoSwitch()` method:\n\n```php\nuse Mistralys\\SSLSwitcher;\n\nSSLSwitcher::autoSwitch('https://domain.extension');\n```\n\nThis will check if the current connection is SSL or not, and redirect to the target URL as needed. Otherwise, the script continues as usual.\n\nNOTE: Any existing request parameters are appended to the target URL, to stay on the same page.\n\n## SSL switching conditions\n\nThe script will redirect to the https version of the website only if the following conditions are met:\n\n1) The script is not run from the command line\n2) The script is not running from localhost\n3) SSL is not enabled\n\n## Using class methods\n\nWhen instantiating the class, you get access to its methods - for example to run some checks\nin your application before doing the switch to https.\n\n```php\nuse Mistralys\\SSLSwitcher;\n\n$switcher = new SSLSwitcher('https://domain.extension');\n\n// Is a switch to https required?\nif($switcher-\u003eisSwitchRequired())\n{\n    // Do something before the redirect\n}\n\n// Redirect\n$switcher-\u003eswitch();\n```\n\n## Utility methods\n\nThe class has a few utility methods that can come in handy.\n\n- `isCLI()` - Is the script running from the command line?\n- `isLocalhost()` - Is the server run as localhost / 127.0.0.1?\n- `isSSLActive()` - Is SSL enabled?\n- `getTargetURL()` - The URL the script would redirect to.\n\n## Disabling the exit call\n\nBy default, the class will call `exit()` after the redirect. If your application needs to handle this instead, the exit can be turned off:\n\n```php\nuse Mistralys\\SSLSwitcher;\n\n$switcher = new SSLSwitcher('https://domain.extension');\n$switcher-\u003esetExitEnabled(false);\n$switcher-\u003eswitch();\n\n// Handle the exit in the script instead\nif($switcher-\u003eisSwitchRequired())\n{\n    exit();\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Fssl-switcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmistralys%2Fssl-switcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmistralys%2Fssl-switcher/lists"}