I have a php script that generates a png image with captcha code as image text.
session_start(); $captchanumber = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz'; $captchanumber = substr(str_shuffle($captchanumber), 0, 8); $_SESSION["code"] = $captchanumber; $image = imagecreatefromjpeg("cap.jpg"); $black = imagecolorallocate($image, 160, 160, 160); $font = '../assets/fonts/OpenSans-Regular.ttf'; imagettftext($image, 20, 0, 35, 27, $black, $font, $captchanumber); header('Content-type: image/png'); imagepng($image); imagedestroy($image);
I want to reload the image via jQuery or JavaScript, so I use something like this:
$(document).ready(function(e) { $('.captcha').click(function(){ alert('yolo'); var id = Math.random(); $(".captcha").replaceWith('<img class="captcha" src="img/captcha.php?id='+id+'" />'); id =''; }); });
field:
<img class="captcha" src="img/captcha.php">
As a first attempt, it works, but after that, if I click on the field again, it will no longer work, and I do not know why.
javascript jquery php image
Petru lebada
source share