{"id":20463816,"url":"https://github.com/lorddashme/php-simple-captcha","last_synced_at":"2025-04-13T08:34:57.008Z","repository":{"id":62519036,"uuid":"147781091","full_name":"LordDashMe/php-simple-captcha","owner":"LordDashMe","description":"A simple captcha package that fit to any type of web application built on php.","archived":false,"fork":false,"pushed_at":"2023-04-01T16:03:04.000Z","size":870,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T18:11:20.986Z","etag":null,"topics":["anti-spam","captcha","free","php","security","simple"],"latest_commit_sha":null,"homepage":"","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/LordDashMe.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":"2018-09-07T06:33:24.000Z","updated_at":"2024-06-24T13:39:54.000Z","dependencies_parsed_at":"2022-11-02T10:45:25.831Z","dependency_job_id":null,"html_url":"https://github.com/LordDashMe/php-simple-captcha","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LordDashMe%2Fphp-simple-captcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LordDashMe%2Fphp-simple-captcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LordDashMe%2Fphp-simple-captcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LordDashMe%2Fphp-simple-captcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LordDashMe","download_url":"https://codeload.github.com/LordDashMe/php-simple-captcha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248684905,"owners_count":21145160,"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":["anti-spam","captcha","free","php","security","simple"],"created_at":"2024-11-15T13:13:12.184Z","updated_at":"2025-04-13T08:34:56.964Z","avatar_url":"https://github.com/LordDashMe.png","language":"PHP","readme":"# PHP Simple Captcha \n\nA simple captcha package that fit to any type of web application built on php.\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/lorddashme/php-simple-captcha.svg?style=flat-square)](https://packagist.org/packages/lorddashme/php-simple-captcha) [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg?style=flat-square)](https://php.net/) [![Coverage Status](https://img.shields.io/coveralls/LordDashMe/php-simple-captcha/master.svg?style=flat-square)](https://coveralls.io/github/LordDashMe/php-simple-captcha?branch=master)\n\n## Sample\n\n![PHP Simple Captcha Sample 1](resources/img/sample1.png) ![PHP Simple Captcha Sample 2](resources/img/sample2.png) ![PHP Simple Captcha Sample 3](resources/img/sample3.png) ![PHP Simple Captcha Sample 4](resources/img/sample4.png)\n\n## Requirement(s)\n\n- PHP version from 5.6.* up to latest.\n\n## Install\n\n- Recommended to install using Composer. Use the command below to install the package:\n\n```txt\ncomposer require lorddashme/php-simple-captcha\n```\n\n## Usage\n\n### List of Available Functions\n\n| Function | Description |\n| -------- | ----------- |\n| ```code(length);``` | Execute the generation of random code base on the given length. \u003cbr\u003e The default length is 5. |\n| ```image();``` | Execute the generation of image and the content will be base on the ```code(length);``` function. |\n| ```getCode();``` | To get the current code generated by the ```code(length);``` method. \u003cbr\u003e Ex. return value ```QwErTyx...``` |\n| ```getImage();``` | To get the current image generated by the ```image();``` function. \u003cbr\u003e Ex. return value ```data:image/png;base64,iVBORw0KGgoAA...``` |\n| ```storeSession();``` | Use to store the generated values in the captcha session. |\n| ```getSession();``` | Use to get the current stored session generated values in the captcha session. This is use to validate the generated code against the user organic inputed code. \u003cbr\u003e Ex. return value ```array('code' =\u003e '...')``` |\n\n- Basic usage:\n\n```php\n\u003c?php\n\ninclude __DIR__  . '/vendor/autoload.php';\n\nuse LordDashMe\\SimpleCaptcha\\Captcha;\n\n// Initialize the captcha class.\n$captcha = new Captcha();\n// Execute the random generation of code.\n$captcha-\u003ecode();\n// Execute the image captcha rendering.\n$captcha-\u003eimage();\n\n// The generated captcha code, something like \"QwErTyx...\"\necho $captcha-\u003egetCode();\n// The generated captcha image that include the code above. \n// The output is base64 data image \"data:image/png;base64,iVBORw0KGgoAA...\"\necho $captcha-\u003egetImage();\n```\n\n- Also can be done by using the code below:\n\n```php\n\u003c?php\n\ninclude __DIR__  . '/vendor/autoload.php';\n\nuse LordDashMe\\SimpleCaptcha\\Facade\\Captcha;\n\n// Initialize the facade captcha class.\nCaptcha::init();\n// Execute the random generation of code.\nCaptcha::code();\n// Execute the image captcha rendering.\nCaptcha::image();\n\n// The generated captcha code, something like \"QwErTyx...\"\necho Captcha::getCode();\n// The generated captcha image that include the code above.  \n// The output is base64 data image \"data:image/png;base64,iVBORw0KGgoAA...\"\necho Captcha::getImage();\n```\n\n### Captcha Session Usage\n\n- The package also provided a simple way to validate the user input code, for example we have a login feature.\n  \n  - Login Page:\n\n    - Initialize the Captcha class together with the code and image generation process.\n\n    - Use the ```storeSession()``` to store the generated details in the captcha session.\n\n    - The stored session details are essential for validating the user input later on.\n\n    ```php\n    \u003c?php\n\n    // login.php\n\n    include __DIR__  . '/vendor/autoload.php';\n\n    use LordDashMe\\SimpleCaptcha\\Captcha;\n\n    $captcha = new Captcha();\n    $captcha-\u003ecode();\n    $captcha-\u003eimage();\n    $captcha-\u003estoreSession();\n\n    ?\u003e\n\n    \u003cform action=\"validate-login.php\" method=\"POST\"\u003e\n\n      ...\n\n      \u003cimg src=\"\u003c?php echo $captcha-\u003egetImage(); ?\u003e\"\u003e\n      \u003cinput type=\"text\" name=\"user_captcha_code\" value=\"\"\u003e\n\n      \u003cinput type=\"submit\" value=\"Login\"\u003e\n\n    \u003c/form\u003e\n    ```\n  - Validation Route:\n\n    - We need to initialize again the Captcha class but now we don't need to initialize the code and image generation.\n\n    - Validate the user inputed captcha code.\n\n    ```php\n    \u003c?php\n\n    // validate-login.php\n\n    include __DIR__  . '/vendor/autoload.php';\n\n    use LordDashMe\\SimpleCaptcha\\Captcha;\n\n    $captcha = new Captcha();\n    $data = $captcha-\u003egetSession(); // return array( 'code' =\u003e 'QwErTyx...' )\n\n    if ($_POST['user_captcha_code'] === $data['code']) {\n        return 'Code is valid!';\n    } else {\n        return 'Code is invalid!';\n    }\n    ```\n\n  - You may also check the [sample](sample) in the root directory of the package that will show you the actual example of implementing captcha class.\n\n### Captcha Configuration\n\n- To change the default config of the class:\n\n```php\n\u003c?php\n\ninclude __DIR__  . '/vendor/autoload.php';\n\nuse LordDashMe\\SimpleCaptcha\\Captcha;\nuse LordDashMe\\SimpleCaptcha\\Facade\\Captcha as CaptchaFacade;\n\n$config = array(\n    'session_name'       =\u003e 'ldm-simple-captcha',\n    'session_index_name' =\u003e 'LDM_SIMPLE_CAPTCHA',\n    'session_https'      =\u003e false,\n    'session_http_only'  =\u003e true,\n    'font_color'         =\u003e '#000',\n    'font_size_min'      =\u003e 26,\n    'font_size_max'      =\u003e 28,\n    'angle_min'          =\u003e 0,\n    'angle_max'          =\u003e 9,\n    'shadow'             =\u003e true,\n    'shadow_color'       =\u003e '#fff',\n    'shadow_offset_x'    =\u003e -3,\n    'shadow_offset_y'    =\u003e 1,\n    'backgrounds' =\u003e array(\n        'bg1.png',\n        'bg2.png',\n        'bg3.png',\n        'bg4.png',\n        'bg5.png',\n        'bg6.png',\n        'bg7.png',\n        'bg8.png'\n    ),\n    'fonts' =\u003e array(\n        'capsmall_clean.ttf'\n    )\n);\n\n$captcha = new Captcha($config);\n\n// Or you can use this style.\n\nCaptchaFacade::init($config);\n```\n\n### Tips\n\n- Overriding the default config:\n\n  - The ```backgrounds``` and ```fonts``` are tightly coupled in the directory structure of the package.\n  \n  - If you want to override the ```backgrounds``` and ```fonts``` you need to extends the Captcha class with your new sub class and override the protected methods of Captcha class for resources directory, ```backgroundsDirectoryPath()``` and ```fontsDirectoryPath```.\n\n    ```php\n    \u003c?php\n\n    include __DIR__  . '/vendor/autoload.php';\n\n    use LordDashMe\\SimpleCaptcha\\Captcha;\n\n    class MyNewCaptcha extends Captcha\n    {\n        public function __construct($config = array())\n        {\n            parent::__construct($config);\n        }\n\n        protected function backgroundsDirectoryPath()\n        {\n            return 'path/to/your/custom/backgrounds/';\n        }\n\n        protected function fontsDirectoryPath()\n        {\n            return 'path/to/your/custom/fonts/'; \n        }\n    }\n    ```\n\n## License\n\nThis package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florddashme%2Fphp-simple-captcha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Florddashme%2Fphp-simple-captcha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florddashme%2Fphp-simple-captcha/lists"}