Javascript 为什么我的验证码刷新链接不起作用?

Javascript 为什么我的验证码刷新链接不起作用?,javascript,php,html,refresh,captcha,Javascript,Php,Html,Refresh,Captcha,我有一个联系人表单(),其中刷新验证码的链接不起作用。我在一个基于PHP的联系人表单中尝试了它,效果很好。这是一个HTML联系人表单。 我遗漏了什么,或者我应该添加什么来让它工作?我需要任何特殊的JavaScript代码吗?(如果您给我一些额外的代码,请解释放在哪里。 没有人回答我的问题,所以我想我会尝试将其转换为PHP,并将其转换为HTML。有什么建议吗? session_start(); //Settings: You can customize the captcha here $imag

我有一个联系人表单(),其中刷新验证码的链接不起作用。我在一个基于PHP的联系人表单中尝试了它,效果很好。这是一个HTML联系人表单。
我遗漏了什么,或者我应该添加什么来让它工作?我需要任何特殊的JavaScript代码吗?(如果您给我一些额外的代码,请解释放在哪里。
没有人回答我的问题,所以我想我会尝试将其转换为PHP,并将其转换为HTML。有什么建议吗?
session_start();
//Settings: You can customize the captcha here
$image_width = 120;
$image_height = 40;
$characters_on_image = 6;
$font = './monofont.ttf';

//The characters that can be used in the CAPTCHA code.
//avoid confusing characters (l 1 and i for example)
$possible_letters = '23456789bcdfghjkmnpqrstvwxyz';
$random_dots = 0;
$random_lines = 20;
$captcha_text_color="0x142864";
$captcha_noice_color = "0x142864";

$code = '';


$i = 0;
while ($i < $characters_on_image) { 
$code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1);
$i++;
}


$font_size = $image_height * 0.75;
$image = @imagecreate($image_width, $image_height);


/* setting the background, text and noise colours here */
$background_color = imagecolorallocate($image, 255, 255, 255);

$arr_text_color = hexrgb($captcha_text_color);
$text_color = imagecolorallocate($image, $arr_text_color['red'], 
    $arr_text_color['green'], $arr_text_color['blue']);

$arr_noice_color = hexrgb($captcha_noice_color);
$image_noise_color = imagecolorallocate($image, $arr_noice_color['red'], 
    $arr_noice_color['green'], $arr_noice_color['blue']);


/* generating the dots randomly in background */
for( $i=0; $i<$random_dots; $i++ ) {
imagefilledellipse($image, mt_rand(0,$image_width),
 mt_rand(0,$image_height), 2, 3, $image_noise_color);
}


/* generating lines randomly in background of image */
for( $i=0; $i<$random_lines; $i++ ) {
imageline($image, mt_rand(0,$image_width), mt_rand(0,$image_height),
 mt_rand(0,$image_width), mt_rand(0,$image_height), $image_noise_color);
}


/* create a text box and add 6 letters code in it */
$textbox = imagettfbbox($font_size, 0, $font, $code); 
$x = ($image_width - $textbox[4])/2;
$y = ($image_height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code);


/* Show captcha image in the page html page */
header('Content-Type: image/jpeg');// defining the image type to be shown in browser widow
imagejpeg($image);//showing the image
imagedestroy($image);//destroying the image instance
$_SESSION['6_letters_code'] = $code;

function hexrgb ($hexstr)
{
  $int = hexdec($hexstr);

  return array("red" => 0xFF & ($int >> 0x10),
           "green" => 0xFF & ($int >> 0x8),
           "blue" => 0xFF & $int);
}
?>
这是密码

HTML
session_start();
//Settings: You can customize the captcha here
$image_width = 120;
$image_height = 40;
$characters_on_image = 6;
$font = './monofont.ttf';

//The characters that can be used in the CAPTCHA code.
//avoid confusing characters (l 1 and i for example)
$possible_letters = '23456789bcdfghjkmnpqrstvwxyz';
$random_dots = 0;
$random_lines = 20;
$captcha_text_color="0x142864";
$captcha_noice_color = "0x142864";

$code = '';


$i = 0;
while ($i < $characters_on_image) { 
$code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1);
$i++;
}


$font_size = $image_height * 0.75;
$image = @imagecreate($image_width, $image_height);


/* setting the background, text and noise colours here */
$background_color = imagecolorallocate($image, 255, 255, 255);

$arr_text_color = hexrgb($captcha_text_color);
$text_color = imagecolorallocate($image, $arr_text_color['red'], 
    $arr_text_color['green'], $arr_text_color['blue']);

$arr_noice_color = hexrgb($captcha_noice_color);
$image_noise_color = imagecolorallocate($image, $arr_noice_color['red'], 
    $arr_noice_color['green'], $arr_noice_color['blue']);


/* generating the dots randomly in background */
for( $i=0; $i<$random_dots; $i++ ) {
imagefilledellipse($image, mt_rand(0,$image_width),
 mt_rand(0,$image_height), 2, 3, $image_noise_color);
}


/* generating lines randomly in background of image */
for( $i=0; $i<$random_lines; $i++ ) {
imageline($image, mt_rand(0,$image_width), mt_rand(0,$image_height),
 mt_rand(0,$image_width), mt_rand(0,$image_height), $image_noise_color);
}


/* create a text box and add 6 letters code in it */
$textbox = imagettfbbox($font_size, 0, $font, $code); 
$x = ($image_width - $textbox[4])/2;
$y = ($image_height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code);


/* Show captcha image in the page html page */
header('Content-Type: image/jpeg');// defining the image type to be shown in browser widow
imagejpeg($image);//showing the image
imagedestroy($image);//destroying the image instance
$_SESSION['6_letters_code'] = $code;

function hexrgb ($hexstr)
{
  $int = hexdec($hexstr);

  return array("red" => 0xFF & ($int >> 0x10),
           "green" => 0xFF & ($int >> 0x8),
           "blue" => 0xFF & $int);
}
?>




姓名:

“id='captchaimg'>
在此处输入上面的代码:

无法读取图像?单击以刷新

PHP
session_start();
//Settings: You can customize the captcha here
$image_width = 120;
$image_height = 40;
$characters_on_image = 6;
$font = './monofont.ttf';

//The characters that can be used in the CAPTCHA code.
//avoid confusing characters (l 1 and i for example)
$possible_letters = '23456789bcdfghjkmnpqrstvwxyz';
$random_dots = 0;
$random_lines = 20;
$captcha_text_color="0x142864";
$captcha_noice_color = "0x142864";

$code = '';


$i = 0;
while ($i < $characters_on_image) { 
$code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1);
$i++;
}


$font_size = $image_height * 0.75;
$image = @imagecreate($image_width, $image_height);


/* setting the background, text and noise colours here */
$background_color = imagecolorallocate($image, 255, 255, 255);

$arr_text_color = hexrgb($captcha_text_color);
$text_color = imagecolorallocate($image, $arr_text_color['red'], 
    $arr_text_color['green'], $arr_text_color['blue']);

$arr_noice_color = hexrgb($captcha_noice_color);
$image_noise_color = imagecolorallocate($image, $arr_noice_color['red'], 
    $arr_noice_color['green'], $arr_noice_color['blue']);


/* generating the dots randomly in background */
for( $i=0; $i<$random_dots; $i++ ) {
imagefilledellipse($image, mt_rand(0,$image_width),
 mt_rand(0,$image_height), 2, 3, $image_noise_color);
}


/* generating lines randomly in background of image */
for( $i=0; $i<$random_lines; $i++ ) {
imageline($image, mt_rand(0,$image_width), mt_rand(0,$image_height),
 mt_rand(0,$image_width), mt_rand(0,$image_height), $image_noise_color);
}


/* create a text box and add 6 letters code in it */
$textbox = imagettfbbox($font_size, 0, $font, $code); 
$x = ($image_width - $textbox[4])/2;
$y = ($image_height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code);


/* Show captcha image in the page html page */
header('Content-Type: image/jpeg');// defining the image type to be shown in browser widow
imagejpeg($image);//showing the image
imagedestroy($image);//destroying the image instance
$_SESSION['6_letters_code'] = $code;

function hexrgb ($hexstr)
{
  $int = hexdec($hexstr);

  return array("red" => 0xFF & ($int >> 0x10),
           "green" => 0xFF & ($int >> 0x8),
           "blue" => 0xFF & $int);
}
?>
session_start();
//设置:您可以在此处自定义验证码
$image_width=120;
$image_height=40;
图像上的$characters\u=6;
$font='./monofont.ttf';
//可在验证码代码中使用的字符。
//避免混淆字符(例如l 1和i)
$APPLICATION_字母='23456789bcdfghjkmnpqrstvwxyz';
$random_dots=0;
$random_line=20;
$captcha\u text\u color=“0x142864”;
$captcha\u noice\u color=“0x142864”;
$code='';
$i=0;
而($i<$characters\u在图像上){
$code.=substr($可能的字母,mt_rand(0,strlen($可能的字母)-1),1);
$i++;
}
$font\u size=$image\u height*0.75;
$image=@imagecreate($image\u-width,$image\u-height);
/*在此处设置背景、文本和噪波颜色*/
$background\u color=imagecolorallocate($image,255,255);
$arr_text_color=hexrgb($captcha_text_color);
$text_color=imagecolorallocate($image,$arr_text_color['red']),在,
$arr_text_color[‘绿色’]、$arr_text_color[‘蓝色’);
$arr_noice_color=hexrgb($captcha_noice_color);
$image\u noise\u color=imagecolorallocate($image,$arr\u noice\u color['red']),
$arr_noice_color[‘绿色’]、$arr_noice_color[‘蓝色’);
/*在背景中随机生成点*/
对于($i=0;$i>0x10),
“绿色”=>0xFF&($int>>0x8),
“蓝色”=>0xFF和$int);
}
?>

在点击锚时调用的
refreshCaptcha()
函数是否更适合发布?在您的页面中,没有
refreshCaptcha()
函数已定义。因此它无论如何都不会工作。而且captcha
img src
属性的值中有
。好吧,我在没有引用的情况下尝试了它,但它仍然不工作。(我忽略了这一点。)有人请告诉我Raj Kamal所说的“没有定义refreshCaptcha()函数”是什么意思吗?“我从一个基于PHP的工作联系人表单中复制/粘贴了代码。它起作用了!但我把它放在HTML中,它没有。为什么。所以它无论如何都不会起作用。而且captcha
img src
属性在其值内有
,好吧,我在没有参考的情况下尝试了它,但仍然不起作用。(我忽略了这一点。)有人告诉我Raj Kamal所说的“没有定义refreshCaptcha()函数”是什么意思吗?我从一个基于PHP的工作联系人表单复制/粘贴了代码。它起作用了!但我把它放在HTML中,它没有。为什么?