Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Captcha
- * -------------------------------------
- *
- * @author iBet7o - <[email protected]>
- */
- class Captcha
- {
- private $_operations = array('+', '-', '*');
- private $_question = array();
- public $answer = NULL;
- private function _operation()
- {
- $this->_question[] = rand(1, 20);
- $this->_question[] = $this->_operations[rand(0, 2)];
- $this->_question[] = rand(1, 20);
- $cal = $this->_question[0];
- if($this->_question[1] == '+')
- {
- $cal += $this->_question[2];
- }
- elseif($this->_question[1] == '-')
- {
- $cal -= $this->_question[2];
- }
- elseif($this->_question[1] == '*')
- {
- $cal *= $this->_question[2];
- }
- $this->_question = implode(' ', $this->_question);
- $this->answer = $cal;
- }
- private function _image()
- {
- header("Content-type: image/png");
- $image = @imagecreate(8 * strlen($this->_question), 15);
- $background_color = imagecolorallocate($image, 255, 255, 255);
- $color = imagecolorallocate($image, 0, 0, 0);
- imagestring($image, 4, 0, 0, $this->_question, $color);
- imagepng($image);
- imagedestroy($image);
- }
- public function show()
- {
- $this->_operation();
- $this->_image();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment