├── .gitignore ├── backgrounds ├── kinda-jean.png ├── white-wave.png ├── cloth-alike.png ├── grey-sandbag.png ├── stitched-wool.png ├── white-carbon.png ├── polyester-lite.png └── 45-degree-fabric.png ├── fonts └── times_new_yorker.ttf ├── composer.json ├── README.md ├── LICENSE.md ├── index.php └── simple-php-captcha.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | simple-php-captcha.sublime-project 3 | simple-php-captcha.sublime-workspace -------------------------------------------------------------------------------- /backgrounds/kinda-jean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasirmturk/simple-php-captcha/HEAD/backgrounds/kinda-jean.png -------------------------------------------------------------------------------- /backgrounds/white-wave.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasirmturk/simple-php-captcha/HEAD/backgrounds/white-wave.png -------------------------------------------------------------------------------- /fonts/times_new_yorker.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasirmturk/simple-php-captcha/HEAD/fonts/times_new_yorker.ttf -------------------------------------------------------------------------------- /backgrounds/cloth-alike.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasirmturk/simple-php-captcha/HEAD/backgrounds/cloth-alike.png -------------------------------------------------------------------------------- /backgrounds/grey-sandbag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasirmturk/simple-php-captcha/HEAD/backgrounds/grey-sandbag.png -------------------------------------------------------------------------------- /backgrounds/stitched-wool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasirmturk/simple-php-captcha/HEAD/backgrounds/stitched-wool.png -------------------------------------------------------------------------------- /backgrounds/white-carbon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasirmturk/simple-php-captcha/HEAD/backgrounds/white-carbon.png -------------------------------------------------------------------------------- /backgrounds/polyester-lite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasirmturk/simple-php-captcha/HEAD/backgrounds/polyester-lite.png -------------------------------------------------------------------------------- /backgrounds/45-degree-fabric.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasirmturk/simple-php-captcha/HEAD/backgrounds/45-degree-fabric.png -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "abeautifulsite/simple-php-captcha", 3 | "description": "A simple PHP CAPTCHA script", 4 | "version": "1.0.1", 5 | "homepage": "http://www.abeautifulsite.net/", 6 | "license": "MIT", 7 | "autoload": { 8 | "files": ["simple-php-captcha.php"] 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A simple PHP CAPTCHA script 2 | 3 | _Written by Cory LaViska for A Beautiful Site, LLC. (http://abeautifulsite.net/)_ 4 | 5 | _Licensed under the MIT license: http://opensource.org/licenses/MIT_ 6 | 7 | ## Demo and Usage 8 | 9 | http://labs.abeautifulsite.net/simple-php-captcha/ 10 | 11 | ## Attribution 12 | 13 | - Special thanks to Subtle Patterns for the patterns used for default backgrounds: http://subtlepatterns.com/ 14 | - Special thanks to dafont.com for providing Times New Yorker: http://www.dafont.com/ -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2017 A Beautiful Site, LLC 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 |
12 |34 | The following code will prepare a CAPTCHA image and keep the code in a session 35 | variable for later use: 36 |
37 | 38 |
39 | <?php
40 | session_start();
41 | include("simple-php-captcha.php");
42 | $_SESSION['captcha'] = simple_php_captcha();
43 | ?>
44 |
45 |
46 |
47 | After the call to simple_php_captcha() above,
48 | $_SESSION['captcha'] will be something like this:
49 |
52 | 55 |56 | 57 |
58 | To display the CAPTCHA image, create an HTML <img> using
59 | $_SESSION['captcha']['image_src'] as the src attribute:
60 |
63 | '; 65 | 66 | ?> 67 |
68 | 69 |
70 | To verify the CAPTCHA value on the next page load (or in an AJAX request), test
71 | against $_SESSION['captcha']['code']. You can use
72 | strtolower() or strtoupper() to perform a
73 | case-insensitive match.
74 |
78 | Configuration is easy and all values are optional. To specify one or more options, 79 | do this: 80 |
81 | 82 |
83 | <?php
84 |
85 | $_SESSION['captcha'] = simple_php_captcha( array(
86 | 'min_length' => 5,
87 | 'max_length' => 5,
88 | 'backgrounds' => array(image.png', ...),
89 | 'fonts' => array('font.ttf', ...),
90 | 'characters' => 'ABCDEFGHJKLMNPRSTUVWXYZabcdefghjkmnprstuvwxyz23456789',
91 | 'min_font_size' => 28,
92 | 'max_font_size' => 28,
93 | 'color' => '#666',
94 | 'angle_min' => 0,
95 | 'angle_max' => 10,
96 | 'shadow' => true,
97 | 'shadow_color' => '#fff',
98 | 'shadow_offset_x' => -1,
99 | 'shadow_offset_y' => 1
100 | ));
101 |
102 | >
103 |
104 |
105 | session_start() before
109 | calling the simple_php_captcha() function
110 | $_SERVER['DOCUMENT_ROOT'] . '/' . [path-to-file])
123 | simple_php_captcha() in the global namespace
130 | $_SESSION['simple-php-captcha'] session variable
133 |