主机上的验证码问题 [英] Captcha problem on host

查看:115
本文介绍了主机上的验证码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经编写了一个创建验证码的PHP代码,我在登录表单中使用它

我的验证码在本地机器上运行但在我的网站上之后主持人它没有显示验证码代码

我检查我的主机,它的gd库是启用

这是我的验证码

hi
I have write a php code that create captcha code and i use it in login form
my captcha code work on local machine but after I my site on host it does not show the captcha code
I check my host and it's gd library is enable
this is my captcha code

<?php
session_start();
function random_string($len=3, $str='')  
 {	for($i=1; $i<=$len; $i++ )   
 {        //generates a random number that will be the ASCII code of the character.
 //We only want numbers (ascii code from 48 to 57) and caps letters. 	
 
 	
 $str.=rand(1,9);	 //If the number is not good we generate another one	
  
 }	return $str;}
 //create the random string using the upper function 
 //(if you want more than 5 characters just modify the parameter)
 $rand_str=random_string(5); 
 // جدا کردن رشته به صورت 5 کاراکتر
  $letter1=substr($rand_str,0,1);
  $letter2=substr($rand_str,1,1);
  $letter3=substr($rand_str,2,1);
  $letter4=substr($rand_str,3,1);
  $letter5=substr($rand_str,4,1);
 //Creates an image from a png file. If you want to use gif or jpg images, 
 //just use the coresponding functions: imagecreatefromjpeg and imagecreatefromgif.
 $image=imagecreatefrompng("pic.png");
 //Get a random angle for each letter to be rotated with.
 // تعیین زاویه نمایش کاراکترها
 $angle1 = rand(0, 0);
 $angle2 = rand(0, 0);
 $angle3 = rand(0, 0);
 $angle4 = rand(0, 0);
 $angle5 = rand(0, 0);
 //Get a random font. (In this examples, the fonts are located in "fonts" directory and named from 1.ttf to 10.ttf)
 // تعیین فونت برای نمایش هر یک از کاراکترها
 $font1 = '../font/'.rand(1,2).'.ttf';
 $font2 = '../font/'.rand(1,2).'.ttf';
 $font3 = '../font/'.rand(1,2).'.ttf';
 $font4 = '../font/'.rand(1,2).'.ttf';
 $font5 = '../font/'.rand(1,2).'.ttf';
 
 //Define a table with colors (the values are the RGB components for each color).
 
 //Get a random color for each letter.
 // تعیین رنگ برای هر یک از کاراکتر ها
 $color1=rand(0,10);
 $color2=rand(0,10);
 $color3=rand(0,10);
 $color4=rand(0,10);
 $color5=rand(0,10);
 //Allocate colors for letters.
 $textColor1 = imagecolorallocate ($image, $color1,10, $color3);
 $textColor2 = imagecolorallocate ($image, $color4,13, $color2);
 $textColor3 = imagecolorallocate ($image, $color2,20, $color1);
 $textColor4 = imagecolorallocate ($image, $color3,10, $color5);
 $textColor5 = imagecolorallocate ($image, $color5,20, $color4);
 
 //Write text to the image using TrueType fonts.
 // تعیین سایز برای هر یک از کاراکترها
 $size1 = rand(17,20);
 $size2 = rand(17,20);
 $size3 = rand(17,20);
 $size4 = rand(17,20);
 $size5 = rand(17,20);
 // تعیین موقعیت نمایش برای هر کدام از کاراکترها
 $y_pos1 = rand(28,28);
 $y_pos2 = rand(28,28);
 $y_pos3 = rand(28,28);
 $y_pos4 = rand(28,28);
 $y_pos5 = rand(28,28);
 
 imagettftext($image, $size1, $angle1, 10, $y_pos1, $textColor1, $font1, $letter1);
 imagettftext($image, $size2, $angle2, 30, $y_pos2, $textColor2, $font2, $letter2);
 imagettftext($image, $size3, $angle3, 55, $y_pos3, $textColor3, $font3, $letter3);
 imagettftext($image, $size4, $angle4, 75, $y_pos4, $textColor4, $font4, $letter4);
 imagettftext($image, $size5, $angle5, 92, $y_pos5, $textColor5, $font5, $letter5);
 
 $_SESSION['captcha'] = $rand_str;
 
 header("C//ontent-type: image/png");
 //Output image to browser
 //imagejpeg($image);
 imagepng($image);
 //Destroys the 
 imagedestroy($image); 



?> 



谢谢你你的帮助


Thanks for your help

推荐答案

len = 3,


str = ' '
{for(
str='') { for(


i = 1;


这篇关于主机上的验证码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆