Простые схемы вязания фото

Простые схемы вязания фото


Простые схемы вязания фото
Implementing a CAPTCHA system to make sure your comment posts is much easier than you would think. First we will make a php file that displays an image and sets a $_SESSION variable up to remember the text in the image. Then all we have to do is check the result of a form submission with the $_SESSION variable.
First lets set up the form to check a CAPTCHA on. <form method="POST"> <img src="CaptchaImage.php" title="Type this text into the box on the right to verify you are human." border="0" /> <input type="text" name="captchaCheck" maxlength="5" size="5"> <br> <button type="submit" id="submit">Check CAPTCHA</button> </form> Notice that I set the maxlength and size parameters to the input field, we will be using a 5 character CAPTCHA and it looks nicer to have an input box that correlates with that.
Now lets add some PHP into the destination page the form goes to when you hit 'submit' (in the code above it's unset so it will default to the same page) to check the response of the CAPTCHA <?php if (isset($_POST['submit'])) { if ($_SESSION['captcha']==$_POST['captchaCheck']) { // if we got here then they entered the correct CAPTCHA in } else { // if we got here, they typed the wrong CAPTCHA in } } ?> Now lets create the CaptchaImage.php to draw the image and set the $_SESSION variable. <?php session_start(); header("Content-Type: image/png"); $box_w = 70; $box_h = 16; $image = ImageCreatetruecolor($box_w,$box_h); $font = 'arial.ttf'; $font_size = 15; $font_angle = 0; $text_x = 0; $text_y = 0; $color_background = ImageColorAllocate($image, 0xFF,0x78,0x15); $color_text = ImageColorAllocate($image, 0xFF,0xE5,0x53); // set up a captcha to check $captcha = ''; $numchars = 5; $chars = 'ACDEFHJKLMPQRTNRWXY23467'; // try to only use characters that aren't easily confused for($i=1; $i <= $numchars; $i++) { $pos = rand(1, strlen($chars)-1); $captcha .= substr($chars,$pos,1); // add the character at that position in the array } imagefilledrectangle($image, 0, 0, $box_w-1,$box_h-1, $color_background); imagettftext($image, $font_size, $font_angle, $text_x, $font_size + $text_y, $color_text, $font, $captcha); imagepng($image); // output the captcha image to the browser imagedestroy($image); $_SESSION["captcha"] = $captcha; ?> The first thing we do is set up the header to tell the browser we will be outputting a PNG image from this PHP file. Then we create an image and set create a CAPTCHA text from random characters. I've chosen to omit certain numbers and letters that people commonly get confused (like 5 and S). The only thing left to do is to render the text to the image but we need a font to be able to do so, I've chosen the arial.ttf font here. There are things you can do to obscure the text and make it less readable and thus harder to do automatic image recognition on like draw lines over the text or rotate the text in random directions. Obscurring the text too much however can result in making real people unable to post comments which can eventually make you lose traffic to your site. Last but not least don't forget to call the imagepng function to render the PNG and output the data to the browser. Of course CAPTCHA isn't the end all be all of deterring spammers. I've found that a combination of different tactics on multiple levels works best including a keyword filter, an Askimet check, CAPTCHA and even an authorization system that emails the webmaster to authorize a post when the comment contains url links. It's also convenient to have a script email you whenever a new comment comes to your site with a link to delete it so that you can immediately respond.

Простые схемы вязания фото

Простые схемы вязания фото

Простые схемы вязания фото

Простые схемы вязания фото

Простые схемы вязания фото

Простые схемы вязания фото

Простые схемы вязания фото

Простые схемы вязания фото

Простые схемы вязания фото