Problem with captcha code

friend
i got a problem with captcha code
i created a captcha.php page contains the code to generate an image with random code
i included the following code where i wanted to show this image with this random code
Security Code

this is the content of the captcha code page

<?php session_start(); $image = imagecreatetruecolor(100,40); $red = imagecolorallocate($image,255,255,255); $yellow = imagecolorallocate($image,rand(1,255),rand(1,255),rand(1,255)); $lines = imagecolorallocatealpha($image,rand(1,200),rand(1,200),rand(1,200),rand(1,60)); $str =''; $i=0; $str=rand(10000,99999); $_SESSION['code']=$str; imagefill($image,0,0,$red); imagettftext($image,20,0,0,30,$yellow,'STENCIL.ttf',$str); for($i=0; $i<30; $i++){ imageline($image,rand(1,200),rand(1,200),rand(1,200),rand(1,200), $lines); } header('content=type: image/gif'); imagegif($image); imagedestroy($image); ?>

and it is working so good when using local host but when using the domain name of my website i don,t see this image with this random code although i can see it very well in the local host
i think the reason is caused by the header function cause when i use it to direct the user to a specific page
when using the function

header(“location: index.php”);
it also used to work well on local host but did not work online and i could avoid it
i tried many times with this code but it did not work
i removed the code to display this image and replaced it to print the session
echo “$_SESSION[‘code’]”; but it used to print the same number every time i refresh the page not a random number every time i refresh it also i gives a random number every time when it is on local host
i need your help with this problem

Well, a quick glance at your code looks like the creation of the GIF is correct.
Also, since it works locally, I will assume there is not an issue with your graphics code.

So, looking into this a bit, researching it for you, I did find that it is most likely a PHP/GD error.
I found this:

GIF support was removed from the GD library in Version 1.6, and added back in Version 2.0.28. This function is not available between these versions. For more information, see the » GD Project site.

You may have one version on your local host and another on your live server.
To find out which version, you can use the GD library INFO command. Just add this line in your PHP code at the very top. When you go to the page, it will display your version info. Check if GIF is false or true.
[php]var_dump(gd_info());[/php]

In case you need to view the GD Project info, I usually just go to the PHP.net site.
Here is a link to it if you need it: http://www.php.net/manual/en/book.image.php

Hope that helps.

Sponsor our Newsletter | Privacy Policy | Terms of Service