Skip to content

Commit

Permalink
Add optional config.inc.php for storing global configuration settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dapphp committed Oct 13, 2015
1 parent def4852 commit 83f1f78
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
59 changes: 59 additions & 0 deletions config.inc.php.SAMPLE
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
Securimage sample config file (rename to config.inc.php to activate)

Place your custom configuration in this file to make settings global so they
are applied to the captcha image, audio playback, and validation.

Using this file is optional but makes settings managing settings easier,
especially when upgrading to a new version.

When a new Securimage object is created, if config.inc.php is found in the
Securimage directory, these settings will be applied *before* any settings
passed to the constructor (so options passed in will override these).

This file is especially useful if you use a custom database or session
configuration and is easier than modifying securimage.php directly.
Any class property from securimage.php can be used here.
*/

return array(
/**** CAPTCHA Appearance Options ****/

'image_width' => 215, // width of captcha image in pixels
'image_height' => 80, // height of captcha image in pixels
'code_length' => 6, // # of characters for captcha code
'image_bg_color' => '#ffffff', // hex color for image background
'text_color' => '#707070', // hex color for captcha text
'line_color' => '#707070', // hex color for lines over text
'num_lines' => 5, // # of lines to draw over text

/**** Code Storage & Database Options ****/

// true if you *DO NOT* want to use PHP sessions at all, false to use PHP sessions
'no_session' => false,

// the PHP session name to use (null for default PHP session name)
// do not change unless you know what you are doing
'session_name' => null,

// change to true to store codes in a database
'use_database' => false,

// database engine to use for storing codes. must have the PDO extension loaded
// Values choices are:
// Securimage::SI_DRIVER_MYSQL, Securimage::SI_DRIVER_SQLITE3, Securimage::SI_DRIVER_PGSQL
'database_driver' => Securimage::SI_DRIVER_MYSQL,

'database_host' => 'localhost', // database server host to connect to
'database_user' => 'root', // database user to connect as
'database_pass' => '', // database user password
'database_name' => 'securimage', // name of database to select (you must create this first or use an existing database)
'database_table' => 'captcha_codes', // database table for storing codes, will be created automatically

// Securimage will automatically create the database table if it is not found
// change to true for performance reasons once database table is up and running
'skip_table_check' => false,

);
19 changes: 19 additions & 0 deletions securimage.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
3.6.2
- Support HTTP range requests with audio playback (iOS requirement)
- Add optional config.inc.php for storing global configuration settings
3.6.1
- Fix copyElement bug in securimage.js for IE Flash fallback
Expand Down Expand Up @@ -907,6 +908,24 @@ public function __construct($options = array())
{
$this->securimage_path = dirname(__FILE__);

if (!is_array($options)) {
trigger_error(
'$options passed to Securimage::__construct() must be an array. ' .
gettype($options) . ' given',
E_USER_WARNING
);
$options = array();
}

// check for and load settings from custom config file
if (file_exists(dirname(__FILE__) . '/config.inc.php')) {
$settings = include dirname(__FILE__) . '/config.inc.php';

if (is_array($settings)) {
$options = array_merge($settings, $options);
}
}

if (is_array($options) && sizeof($options) > 0) {
foreach($options as $prop => $val) {
if ($prop == 'captchaId') {
Expand Down

0 comments on commit 83f1f78

Please sign in to comment.