Esempio n. 1
0
 /**
  * Generate a new captcha ID or retrieve the current ID (if exists).
  *
  * @param bool $new If true, generates a new challenge and returns and ID.  If false, the existing captcha ID is returned, or null if none exists.
  * @param array $options Additional options to be passed to Securimage.
  *   $options must include database settings if they are not set directly in securimage.php
  *
  * @return null|string Returns null if no captcha id set and new was false, or the captcha ID
  */
 public static function getCaptchaId($new = true, array $options = array())
 {
     if (is_null($new) || (bool) $new == true) {
         $id = sha1(uniqid($_SERVER['REMOTE_ADDR'], true));
         $opts = array('no_session' => true, 'use_database' => true);
         if (sizeof($options) > 0) {
             $opts = array_merge($options, $opts);
         }
         $si = new self($opts);
         Securimage::$_captchaId = $id;
         $si->createCode();
         return $id;
     } else {
         return Securimage::$_captchaId;
     }
 }
Esempio n. 2
0
function process_si_contact_form()
{
    $_SESSION['ctform'] = array();
    // re-initialize the form session data
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && @$_POST['do'] == 'contact') {
        // if the form has been submitted
        foreach ($_POST as $key => $value) {
            if (!is_array($key)) {
                // sanitize the input data
                if ($key != 'ct_message') {
                    $value = strip_tags($value);
                }
                $_POST[$key] = htmlspecialchars(stripslashes(trim($value)));
            }
        }
        $name = @$_POST['ct_name'];
        // name from the form
        $email = @$_POST['ct_email'];
        // email from the form
        $URL = @$_POST['ct_URL'];
        // url from the form
        $message = @$_POST['ct_message'];
        // the message from the form
        $captcha = @$_POST['ct_captcha'];
        // the user's entry for the captcha code
        $name = substr($name, 0, 64);
        // limit name to 64 characters
        $errors = array();
        // initialize empty error array
        if (isset($GLOBALS['DEBUG_MODE']) && $GLOBALS['DEBUG_MODE'] == false) {
            // only check for errors if the form is not in debug mode
            if (strlen($name) < 3) {
                // name too short, add error
                $errors['name_error'] = 'Your name is required';
            }
            if (strlen($email) == 0) {
                // no email address given
                $errors['email_error'] = 'Email address is required';
            } else {
                if (!preg_match('/^(?:[\\w\\d-]+\\.?)+@(?:(?:[\\w\\d]\\-?)+\\.)+\\w{2,63}$/i', $email)) {
                    // invalid email format
                    $errors['email_error'] = 'Email address entered is invalid';
                }
            }
            if (strlen($message) < 20) {
                // message length too short
                $errors['message_error'] = 'Your message must be longer than 20 characters';
            }
        }
        // Only try to validate the captcha if the form has no errors
        // This is especially important for ajax calls
        if (sizeof($errors) == 0) {
            $securimage = new Securimage();
            if ($securimage->check($captcha) == false) {
                $errors['captcha_error'] = 'Incorrect security code entered<br />';
            }
        }
        if (sizeof($errors) == 0) {
            // no errors, send the form
            $time = date('r');
            $message = "A message was submitted from the contact form.  The following information was provided.<br /><br />" . "<em>Name: {$name}</em><br />" . "<em>Email: {$email}</em><br />" . "<em>URL: {$URL}</em><br />" . "<em>Message:</em><br />" . "<pre>{$message}</pre>" . "<br /><br /><em>IP Address:</em> {$_SERVER['REMOTE_ADDR']}<br />" . "<em>Time:</em> {$time}<br />" . "<em>Browser:</em> {$_SERVER['HTTP_USER_AGENT']}<br />";
            $message = wordwrap($message, 70);
            if (isset($GLOBALS['DEBUG_MODE']) && $GLOBALS['DEBUG_MODE'] == false) {
                // send the message with mail()
                mail($GLOBALS['ct_recipient'], $GLOBALS['ct_msg_subject'], $message, "From: {$GLOBALS['ct_recipient']}\r\nReply-To: {$email}\r\nContent-type: text/html; charset=UTF-8\r\nMIME-Version: 1.0");
            }
            $_SESSION['ctform']['timetosolve'] = $securimage->getTimeToSolve();
            $_SESSION['ctform']['error'] = false;
            // no error with form
            $_SESSION['ctform']['success'] = true;
            // message sent
        } else {
            // save the entries, this is to re-populate the form
            $_SESSION['ctform']['ct_name'] = $name;
            // save name from the form submission
            $_SESSION['ctform']['ct_email'] = $email;
            // save email
            $_SESSION['ctform']['ct_URL'] = $URL;
            // save URL
            $_SESSION['ctform']['ct_message'] = $message;
            // save message
            foreach ($errors as $key => $error) {
                // set up error messages to display with each field
                $_SESSION['ctform'][$key] = "<span class=\"error\">{$error}</span>";
            }
            $_SESSION['ctform']['error'] = true;
            // set error floag
        }
    }
    // POST
}
Esempio n. 3
0
 * If you found this script useful, please take a quick moment to rate it.<br />
 * http://www.hotscripts.com/rate/49400.html  Thanks.
 *
 * @link http://www.phpcaptcha.org Securimage PHP CAPTCHA
 * @link http://www.phpcaptcha.org/latest.zip Download Latest Version
 * @link http://www.phpcaptcha.org/Securimage_Docs/ Online Documentation
 * @copyright 2012 Drew Phillips
 * @author Drew Phillips <*****@*****.**>
 * @version 3.5.2 (Feb 15, 2014)
 * @package Securimage
 *
 */
// if using database, adjust these options as necessary and change $img = new Securimage(); to $img = new Securimage($options);
// see test.mysql.php or test.sqlite.php for examples
$options = array('use_database' => true, 'database_name' => '', 'database_user' => '', 'database_driver' => Securimage::SI_DRIVER_MYSQL);
$img = new Securimage();
// Other audio settings
//$img->audio_use_sox   = true;
//$img->audio_use_noise = true;
//$img->degrade_audio   = false;
//$img->sox_binary_path = 'sox';
//Securimage::$lame_binary_path = '/usr/bin/lame'; // for mp3 audio support
// To use an alternate language, uncomment the following and download the files from phpcaptcha.org
// $img->audio_path = $img->securimage_path . '/audio/es/';
// If you have more than one captcha on a page, one must use a custom namespace
// $img->namespace = 'form2';
// set namespace if supplied to script via HTTP GET
if (!empty($_GET['namespace'])) {
    $img->setNamespace($_GET['namespace']);
}
// mp3 or wav format
Esempio n. 4
0
function process_si_contact_form()
{
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && @$_POST['do'] == 'contact') {
        // if the form has been submitted
        foreach ($_POST as $key => $value) {
            if (!is_array($key)) {
                // sanitize the input data
                if ($key != 'ct_message') {
                    $value = strip_tags($value);
                }
                $_POST[$key] = htmlspecialchars(stripslashes(trim($value)));
            }
        }
        $name = @$_POST['ct_name'];
        // name from the form
        $email = @$_POST['ct_email'];
        // email from the form
        $URL = @$_POST['ct_URL'];
        // url from the form
        $message = @$_POST['ct_message'];
        // the message from the form
        $captcha = @$_POST['ct_captcha'];
        // the user's entry for the captcha code
        $name = substr($name, 0, 64);
        // limit name to 64 characters
        $errors = array();
        // initialize empty error array
        if (isset($GLOBALS['DEBUG_MODE']) && $GLOBALS['DEBUG_MODE'] == false) {
            // only check for errors if the form is not in debug mode
            if (strlen($name) < 3) {
                // name too short, add error
                $errors['name_error'] = 'Your name is required';
            }
            if (strlen($email) == 0) {
                // no email address given
                $errors['email_error'] = 'Email address is required';
            } else {
                if (!preg_match('/^(?:[\\w\\d-]+\\.?)+@(?:(?:[\\w\\d]\\-?)+\\.)+\\w{2,4}$/i', $email)) {
                    // invalid email format
                    $errors['email_error'] = 'Email address entered is invalid';
                }
            }
            if (strlen($message) < 20) {
                // message length too short
                $errors['message_error'] = 'Please enter a message';
            }
        }
        // Only try to validate the captcha if the form has no errors
        // This is especially important for ajax calls
        if (sizeof($errors) == 0) {
            $securimage = new Securimage();
            if ($securimage->check($captcha) == false) {
                $errors['captcha_error'] = 'Incorrect security code entered';
            }
        }
        if (sizeof($errors) == 0) {
            // no errors, send the form
            $time = date('r');
            $message = "A message was submitted from the contact form.  The following information was provided.<br /><br />" . "Name: {$name}<br />" . "Email: {$email}<br />" . "URL: {$URL}<br />" . "Message:<br />" . "<pre>{$message}</pre>" . "<br /><br />IP Address: {$_SERVER['REMOTE_ADDR']}<br />" . "Time: {$time}<br />" . "Browser: {$_SERVER['HTTP_USER_AGENT']}<br />";
            if (isset($GLOBALS['DEBUG_MODE']) && $GLOBALS['DEBUG_MODE'] == false) {
                // send the message with mail()
                mail($GLOBALS['ct_recipient'], $GLOBALS['ct_msg_subject'], $message, "From: {$GLOBALS['ct_recipient']}\r\nReply-To: {$email}\r\nContent-type: text/html; charset=ISO-8859-1\r\nMIME-Version: 1.0");
            }
            $return = array('error' => 0, 'message' => 'OK');
            die(json_encode($return));
        } else {
            $errmsg = '';
            foreach ($errors as $key => $error) {
                // set up error messages to display with each field
                $errmsg .= " - {$error}\n";
            }
            $return = array('error' => 1, 'message' => $errmsg);
            die(json_encode($return));
        }
    }
    // POST
}
Esempio n. 5
0
 * If you found this script useful, please take a quick moment to rate it.<br />
 * http://www.hotscripts.com/rate/49400.html  Thanks.
 *
 * @link http://www.phpcaptcha.org Securimage PHP CAPTCHA
 * @link http://www.phpcaptcha.org/latest.zip Download Latest Version
 * @link http://www.phpcaptcha.org/Securimage_Docs/ Online Documentation
 * @copyright 2013 Drew Phillips
 * @author Drew Phillips <*****@*****.**>
 * @version 3.5.2 (Feb 15, 2014)
 * @package Securimage
 *
 */
// Remove the "//" from the following line for debugging problems
// error_reporting(E_ALL); ini_set('display_errors', 1);
//require_once dirname(__FILE__) . '/securimage.php';
$img = new Securimage();
// You can customize the image by making changes below, some examples are included - remove the "//" to uncomment
//$img->ttf_file        = './Quiff.ttf';
//$img->captcha_type    = Securimage::SI_CAPTCHA_MATHEMATIC; // show a simple math problem instead of text
//$img->case_sensitive  = true;                              // true to use case sensitve codes - not recommended
//$img->image_height    = 90;                                // height in pixels of the image
//$img->image_width     = $img->image_height * M_E;          // a good formula for image size based on the height
//$img->perturbation    = .75;                               // 1.0 = high distortion, higher numbers = more distortion
//$img->image_bg_color  = new Securimage_Color("#0099CC");   // image background color
//$img->text_color      = new Securimage_Color("#EAEAEA");   // captcha text color
//$img->num_lines       = 8;                                 // how many lines to draw over the image
//$img->line_color      = new Securimage_Color("#0000CC");   // color of lines over the image
//$img->image_type      = SI_IMAGE_JPEG;                     // render as a jpeg image
//$img->signature_color = new Securimage_Color(rand(0, 64),
//                                             rand(64, 128),
//                                             rand(128, 255));  // random signature color