{"id":15470512,"url":"https://github.com/mehdibo/codeigniter-recaptcha","last_synced_at":"2025-09-01T08:10:12.711Z","repository":{"id":62526752,"uuid":"97093089","full_name":"mehdibo/Codeigniter-recaptcha","owner":"mehdibo","description":"CodeIgniter library to use Google's reCAPTCHA V2","archived":false,"fork":false,"pushed_at":"2022-06-15T13:07:06.000Z","size":56,"stargazers_count":28,"open_issues_count":0,"forks_count":21,"subscribers_count":5,"default_branch":"develop","last_synced_at":"2025-07-29T20:18:25.843Z","etag":null,"topics":["codeigniter-library","codeigniter-recaptcha","google-recaptcha","php","recaptcha","recaptcha-api","recaptcha-verification","recaptcha-widget","recaptchav2"],"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/mehdibo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-13T07:26:17.000Z","updated_at":"2023-02-10T18:27:03.000Z","dependencies_parsed_at":"2022-11-02T15:31:40.079Z","dependency_job_id":null,"html_url":"https://github.com/mehdibo/Codeigniter-recaptcha","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/mehdibo/Codeigniter-recaptcha","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdibo%2FCodeigniter-recaptcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdibo%2FCodeigniter-recaptcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdibo%2FCodeigniter-recaptcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdibo%2FCodeigniter-recaptcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mehdibo","download_url":"https://codeload.github.com/mehdibo/Codeigniter-recaptcha/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdibo%2FCodeigniter-recaptcha/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273093515,"owners_count":25044437,"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-09-01T02:00:09.058Z","response_time":120,"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":["codeigniter-library","codeigniter-recaptcha","google-recaptcha","php","recaptcha","recaptcha-api","recaptcha-verification","recaptcha-widget","recaptchav2"],"created_at":"2024-10-02T02:05:11.403Z","updated_at":"2025-09-01T08:10:12.678Z","avatar_url":"https://github.com/mehdibo.png","language":"PHP","readme":"# Codeigniter-recaptcha\nThis library makes it easy to use [Google's reCAPTCHA V2](https://developers.google.com/recaptcha/intro)\n\n## Contents\n\n* [Installation](#installation)\n  * [Via composer](#via-composer)\n  * [Manually](#manually)\n* [Documentation](#documentation)\n  * [Getting the keys](#getting-the-keys)\n  * [Setting the keys](#setting-the-keys)\n  * [Loading the library](#loading-the-library)\n  * [Setting parameters](#setting-parameters)\n  * [Creating the reCAPTCHA box](#creating-the-recaptcha-box)\n  * [Validating the reCAPTCHA](#validating-the-recaptcha)\n* [Example](#example)\n* [Contributing](#contributing)\n\n## Installation\n\n### Via composer\nIf you have composer installed you can run\n\n```sh\ncomposer require mehdibo/codeigniter-recaptcha\n```\n\nCopy the content of [`config/recaptcha.php`](/config/recaptcha.php) to `application/config/recaptcha.php`\n\n**First time using composer**\n\nOpen a terminal (commands in windows), the commands here are for linux but you can find the equivalent in windows.\n\n1. First thing you should do is [install composer](https://getcomposer.org/doc/00-intro.md)\n\n2. Go to your application folder: `cd application`\n\n3. Install the library: `composer require mehdibo/codeigniter-recaptcha`\n\n4. Copy the content of [`config/recaptcha.php`](/config/recaptcha.php) to your `application/config/recaptcha.php`\n\n5. Go to `application/config/config.php` and set `composer_autoload` to `TRUE`\n\n6. That's it! check the [Documentation](#documentation) for more details.\n\n### Manually\n\n1. Download the [latest release](https://github.com/mehdibo/Codeigniter-recaptcha/releases).\n\n2. Copy `libraries/Recaptcha.php` to `application/libraries` and `config/recaptcha.php` to `application/config`.\n\n3. Load the library using the Codeigniter loader `$this-\u003eload-\u003elibrary('recaptcha')`, check the [example](#example).\n\n4. See the [documentation](#documentation) for usage.\n\n## Documentation\n\n### Getting the keys\nTo use the reCAPTCHA you need a pair of keys (A secret and site keys), these can be obtained from Google by going to:\nhttps://www.google.com/recaptcha/admin\n\nAnd registering a new website, make sure you tick the \"reCAPTCHA V2\" option.\n\n### Setting the keys\nThere are three ways to pass the keys to the library\n  \n**In the config file**\n\nYou can set the keys by editing the `config/recaptcha.php` config file\n\n**Using the CodeIgniter loader**\n\nBy passing an array of configs to the CodeIgniter loader, more details in the \"[Loading the library](#loading-the-library)\" section.\n\n**Using the `set_keys` method**\n\nYou can pass the keys to the `set_keys` methods (after loading the library) like this:\n\n```php\n$this-\u003erecaptcha-\u003eset_keys('site_key', 'secret_key');\n```\n\n### Loading the library\nYou can load the library like any other library:\n```php\n$this-\u003eload-\u003elibrary('recaptcha', $config);\n```\n\nOr if installed via composer:\n```php\n$recaptcha = new Recaptcha($config);\n```\nAnd you can access the methods like this:\n```php\n$recaptcha-\u003emethod_name();\n```\n\n\nThe `$config` argument is *optional*, It can have an array of configs to the library.\n\n`$config` options are:\n* `$config['site_key']` - Site key provided by Google\n* `$config['secret_key']` - Secret key provided by Google\n* `$config['parameters']` - An associative array of parameters and their value, `'parameter-name' =\u003e 'value'`, more details about parameters in the \"[Setting parameters](#setting-parameters)\" section.\n\n### Setting parameters\nYou can set the parameters ([g-recaptcha tag attributes and grecaptcha.render parameters](https://developers.google.com/recaptcha/docs/display#render_param)) by using the `set_parameter` or `set_parameters` methods.\n\nTo set a parameter you can do it by calling:\n```php\n$this-\u003erecaptcha-\u003eset_parameter('parameter_name', 'value');\n```\n\nOr by passing an array to `set_parameters`:\n\n```php\n$this-\u003erecaptcha-\u003eset_parameters($params);\n```\n\nWhere `$params` is an associative array of `param_name =\u003e value`.\n\nWhen passing a parameter, omit the `data-` part, for example,\nIf you want to set the `data-theme` parameter to `dark` you will do it like this:\n```php\n$this-\u003erecaptcha-\u003eset_parameter('theme', 'dark');\n```\n\n### Creating the reCAPTCHA box\nTo create the reCAPTCHA box's HTML code call the `create_box` method:\n\n```php\n$this-\u003erecaptcha-\u003ecreate_box($attributes)\n```\n\nThis method takes one optional parameter, an array of custom attributes, for example:\n```php\n$attributes = array(\n    'class' =\u003e 're-box',\n    'id' =\u003e 'an-id'\n)\n```\n\n**Notice:** You need to have the reCAPTCHA JS code included in your code:\n\n```html\n\u003cscript src='https://www.google.com/recaptcha/api.js'\u003e\u003c/script\u003e\n```\n\n### Validating the reCAPTCHA\nThe `is_valid` method can be called to verify that the user passed the reCAPTCHA's puzzle.\n\n```php\n$this-\u003erecaptcha-\u003eis_valid($response, $ip)\n```\nthis method takes two optional parameters:\n\n`$response` - the response submitted by the user, set to `NULL` so that it'll be taken automatically from the POST data\n\n`$ip` - the user IP to be sent to Google's server\n\nSet to `FALSE` to not send the IP\n\nSet to `NULL` to get the user's IP automatically\n  \nAnd it returns an array:\n\n```\n'success' =\u003e TRUE if the recaptcha was passed,\n\n'error' =\u003e TRUE if there was an error connecting to the server,\n\n'error_message' =\u003e If error is true, this contains the message returned by curl,\n\n'challenge_ts' =\u003e  timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)\n\n'hostname' =\u003e the hostname of the site where the reCAPTCHA was solved\n\n'error-codes' =\u003e error codes returned by Google if there are any\n```\n\n## Example\nHere is a quick example to use the **Codeigniter-recaptcha** library.\n\n### Installed via composer\n\n**The Controller**\n```php\n\u003c?php\n\nclass Form extends CI_Controller {\n\n\tpublic function index()\n\t{\n\t\t/*\n\t\t Load the reCAPTCHA library.\n\t\t You can pass the keys here by passing an array to the class.\n\t\t Check the \"Setting the keys\" section for more details\n\t\t*/\n\t\t$recaptcha = new Recaptcha();\n\n\t\t/*\n\t\t Create the reCAPTCHA box.\n\t\t You can pass an array of attributes to this method.\n\t\t Check the \"Creating the reCAPTCHA box\" section for more details\n\t\t*/\n\t\t$box = $recaptcha-\u003ecreate_box();\n\n\t\t// Check if the form is submitted\n\t\tif($this-\u003einput-\u003epost('action') === 'submit')\n\t\t{\n\t\t\t/*\n\t\t\t Check if the reCAPTCHA was solved\n\t\t\t You can pass arguments to the `is_valid` method,\n\t\t\t but it should work fine without any.\n\t\t\t Check the \"Validating the reCAPTCHA\" section for more details\n\t\t\t*/\n\t\t\t$is_valid =$recaptcha-\u003eis_valid();\n\n\t\t\tif($is_valid['success'])\n\t\t\t{\n\t\t\t\techo \"reCAPTCHA solved\";\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\techo \"reCAPTCHA not solved/an error occured\";\n\t\t\t}\n\t\t}\n\n\t\t$this-\u003eload-\u003eview('form', ['recaptcha' =\u003e $box]);\n\t}\n```\n\n### Installed manually\n\n**The Controller**\n```php\n\u003c?php\n\nclass Form extends CI_Controller {\n\n\tpublic function index()\n\t{\n\t\t/*\n\t\t Load the reCAPTCHA library.\n\t\t You can pass the keys here by passing an array to the loader.\n\t\t Check the \"Setting the keys\" section for more details\n\t\t*/\n\t\t$this-\u003eload-\u003elibrary('recaptcha');\n\n\t\t/*\n\t\t Create the reCAPTCHA box.\n\t\t You can pass an array of attributes to this method.\n\t\t Check the \"Creating the reCAPTCHA box\" section for more details\n\t\t*/\n\t\t$recaptcha = $this-\u003erecaptcha-\u003ecreate_box();\n\n\t\t// Check if the form is submitted\n\t\tif($this-\u003einput-\u003epost('action') === 'submit')\n\t\t{\n\t\t\t/*\n\t\t\t Check if the reCAPTCHA was solved\n\t\t\t You can pass arguments to the `is_valid` method,\n\t\t\t but it should work fine without any.\n\t\t\t Check the \"Validating the reCAPTCHA\" section for more details\n\t\t\t*/\n\t\t\t$is_valid = $this-\u003erecaptcha-\u003eis_valid();\n\n\t\t\tif($is_valid['success'])\n\t\t\t{\n\t\t\t\techo \"reCAPTCHA solved\";\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\techo \"reCAPTCHA not solved/an error occured\";\n\t\t\t}\n\t\t}\n\n\t\t$this-\u003eload-\u003eview('form', ['recaptcha' =\u003e $recaptcha]);\n\t}\n```\n---\n\n**The view**\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n\t\u003ctitle\u003eCodeIgniter reCAPTCHA\u003c/title\u003e\n\t\u003c!-- reCAPTCHA JavaScript API --\u003e\n\t\u003cscript src='https://www.google.com/recaptcha/api.js'\u003e\u003c/script\u003e\n\u003c/head\u003e\n\n\u003cbody\u003e\n\t\u003cform action=\"/path/to/controller\"\u003e\n\t\t\u003c?=$recaptcha?\u003e\n\t\t\u003cbutton type=\"submit\" name=\"action\" value=\"submit\"\u003eSubmit\u003c/button\u003e\n\t\u003c/form\u003e\n\u003c/body\u003e\n\n\u003c/html\u003e\n```\n\n## Contributing \nAll contributions are welcome! Just make sure you read [How to contribute](https://github.com/mehdibo/Codeigniter-recaptcha/blob/master/CONTRIBUTING.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehdibo%2Fcodeigniter-recaptcha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmehdibo%2Fcodeigniter-recaptcha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehdibo%2Fcodeigniter-recaptcha/lists"}