how to delete captcha_pi.php |
[eluser]cutzi[/eluser]
this is my website http://www.faceinabox.co.cc/ and this is the captcha_pi.php file Here is an example of usage with a DB. On the page where the captcha will be shown you'll have something like this: $this->load->plugin('captcha'); $vals = array( 'img_path' => './captcha/', 'img_url' => 'http://www.your-site.com/captcha/' ); $cap = create_captcha($vals); $data = array( 'captcha_id' => '', 'captcha_time' => $cap['time'], 'ip_address' => $this->input->ip_address(), 'word' => $cap['word'] ); $query = $this->db->insert_string('captcha', $data); $this->db->query($query); echo 'Submit the word you see below:'; echo $cap['image']; echo '<input type="text" name="captcha" value="" />'; Then, on the page that accepts the submission you'll have something like this: // First, delete old captchas $expiration = time()-7200; // Two hour limit $DB->query("DELETE FROM captcha WHERE captcha_time < ".$expiration); // Then see if a captcha exists: $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND date > ?"; $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); $query = $this->db->query($sql, $binds); $row = $query->row(); if ($row->count == 0) { echo "You must submit the word that appears in the image"; } */ /** |========================================================== | Create Captcha |========================================================== | */ function create_captcha($data = '', $img_path = '', $img_url = 'http://www.faceinabox.co.cc/captcha/1204095017.19.jpg', $font_path = 'CodeIgniterCore/fonts/texb.ttf') { $defaults = array('word' => '', 'img_path' => '', 'img_url' => 'http://www.faceinabox.co.cc/captcha/1204095017.19.jpg', 'img_width' => '150', 'img_height' => '30', 'font_path' => 'CodeIgniterCore/fonts/texb.ttf', 'expiration' => 7200); foreach ($defaults as $key => $val) { if ( ! is_array($data)) { if ( ! isset($$key) OR $$key == '') { $$key = $val; } } else { $$key = ( ! isset($data[$key])) ? $val : $data[$key]; } } if ($img_path == '' OR $img_url == '') { return FALSE; } if ( ! @is_dir($img_path)) { return FALSE; } if ( ! is_really_writable($img_path)) { return FALSE; } if ( ! extension_loaded('gd')) { return FALSE; } // ----------------------------------- // Remove old images // ----------------------------------- list($usec, $sec) = explode(" ", microtime()); $now = ((float)$usec + (float)$sec); $current_dir = @opendir($img_path); while($filename = @readdir($current_dir)) { if ($filename != "." and $filename != ".." and $filename != "index.html") { $name = str_replace(".jpg", "", $filename); if (($name + $expiration) < $now) { @unlink($img_path.$filename); } } } @closedir($current_dir); // ----------------------------------- // Do we have a "word" yet? // ----------------------------------- if ($word == '58327') { $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $str = ''; for ($i = 0; $i < 8; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } $word = $str; } // ----------------------------------- // Determine ang |
Messages In This Thread |
how to delete captcha_pi.php - by El Forum - 03-23-2009, 03:42 PM
how to delete captcha_pi.php - by El Forum - 03-23-2009, 07:04 PM
how to delete captcha_pi.php - by El Forum - 03-23-2009, 07:22 PM
how to delete captcha_pi.php - by El Forum - 03-23-2009, 07:23 PM
how to delete captcha_pi.php - by El Forum - 03-23-2009, 07:28 PM
how to delete captcha_pi.php - by El Forum - 03-24-2009, 02:33 AM
how to delete captcha_pi.php - by El Forum - 03-24-2009, 02:39 AM
how to delete captcha_pi.php - by El Forum - 03-24-2009, 06:54 AM
|