Jump to content

cromine87

Members
  • Posts

    5
  • Joined

  • Last visited

cromine87's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Not working meaning nothing appears in the browser. This is my code that I wrote, I'm very new at PHP and don't know this stuff very well at all, I apoligize.
  2. I'm not sure, It's not working for me on my machine. Trying to figure out what the problem is.
  3. I have been trying to create this captcha class and then display a captcha image to a webpage. My code has lots of issues I'm sure, but I was wondering if anyone could help me figure out what I am doing wrong. My current code is as follows: <?php class Captcha { private $teststring = ''; private $strlength = 0; private $backcolor = 0; private $textcolor = 0; private $image = null; function __construct($w=200,$l=50) { $this->image = imageCreate($w,$l); } private function defineCaptcha() { $captchastr = ""; for($i=1;$i<=$strlength;$i++) { $textornumber = rand(1,3); if($textornumber == 1) { $captchastr .= chr(rand(49,57)); } if($textornumber == 2) { $captchastr .= chr(rand(65,78)); } if($textornumber == 3) { $captchastr .= chr(rand(80,90)); } } } private function textToImage() { $randcolR = rand(100,230); $randcolG = rand(100,230); $randcolB = rand(100,230); //initialize image $captcha is handle dimensions 200,50 $captcha = imageCreate(200,50); $backcolor = imageColorAllocate($captcha, $randcolR, $randcolG, $randcolB); $textcolor = imageColorAllocate($captcha, ($randcolR - 20), ($randcolG - 20), ($randcolB - 20)); for($i=1;$i<=$strlength;$i++) { $clockorcounter = rand(1,2); if ($clockorcounter == 1) { $rotangle = rand(0,45); } if ($clockorcounter == 2) { $rotangle = rand(315,360); } //$i*25 spaces the characters 25 pixels apart imagettftext($captcha,rand(14,20),$rotangle,($i*25),30,$textcolor,FONT,substr($captchastr,($i-1),1)); } } private function drawEllipses() { for($i=1; $i<=4;$i++) { imageellipse($captcha,rand(1,200),rand(1,50),rand(50,100),rand(12,25),$textcolor); } for($i=1; $i<=4;$i++) { imageellipse($captcha,rand(1,200),rand(1,50),rand(50,100),rand(12,25),$backcolor); } } private function finishingTouch() { $_SESSION['testString'] = $this->testString; //Send the headers (at last possible time) ob_start(); //header('Content-type: image/png'); //Output the image as a PNG //Delete the image from memory //imageDestroy($this->image); imagePNG($this->image); $output = ob_get_contents(); ob_end_clean(); return $output; } public function makeImage() { $this->defineCaptcha(); $this->textToImage(); $this->drawEllipses(); $this->finishIt(); } } ?> <? session_start(); $myCaptcha = new Captcha(); //sentinal variable $continue = true; if(isset($_POST['submit'])) { if($_POST['code'] == $_SESSION['captchastr']) { echo "Success!!"; $continue = false; } else { echo "Please try again!!"; $continue = true; } } ?> <? if($continue == true) { //this is the code to produce the image in the HTML // calls the public method that creates validation image $image = $myCaptcha->makeImage(); $image = base64_encode($image); //heredoc to hold html output //$image = $_SESSION['image']; $outString = <<<EOF <html> <head> <title>Reverse Turing Test</title> </head> <body> <img src="data:image/png;base64, {$image}"> <form name="myform" action="" method="POST"> <input type="text" name="userInput" value="" /><br /> <input type="submit" name="submit" value="submit" /> </form> </body> </html> EOF; echo $outString; } ?>
  4. Theses are both great ideas of how to do this thank you for your help!
  5. I'm very new at php and need help converting this random name generator code into a php class. This is the current php code: <?php $vowels = array("a", "e", "o", "u"); $consonants = array("b", "c", "d", "v", "g", "t"); function randVowel() { global $vowels; return $vowels[array_rand($vowels, 1)]; } function randConsonant() { global $consonants; return $consonants[array_rand($consonants, 1)]; } echo ucfirst("" . randConsonant() . "" . randVowel() . "" . "" . randConsonant() . "" . randVowel() . "" . randVowel() . ""); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.