A security image question

Hi, I’ve been working on a web site of mine for a little over a month now, but I’ve come across an issue that I can’t seem to figure out. When calling the SRC for the security image, the image displays fine, but no text. GD is enabled on my web host and ‘functions.php’ exists in the same directory, as does the CENTAUR.TTF font file. It should work fine, because it works without issue on my localhost server, but not on my domain name (through FatCow).

[php]

<?php include 'functions.php'; //Generate Reference ID if (isset($_GET["refid"]) && $_GET["refid"]!="") { $referenceid = stripslashes($_GET["refid"]); } else { $referenceid = md5(mktime()*rand()); } //Select Font $font = "CENTAUR.ttf"; //Create Image $im = ImageCreateFromPNG("images/bg1.png"); //Generate the random string $chars = array("a","A","b","B","c","C","d","D","e","E","f","F","g","G", "h","H","i","I","j","J","k", "K","l","L","m","M","n","N","o","O","p","P","q","Q","r", "R","s","S","t","T","u","U","v", "V","w","W","x","X","y","Y","z","Z","1","2","3","4","5", "6","7","8","9"); $length = 8; $textstr = ""; for ($i=0; $i<$length; $i++) { $textstr .= $chars[rand(0, count($chars)-1)]; } //Create random size, angle, and dark color $size = rand(14, 16); $angle = rand(-5, 5); $color = ImageColorAllocate($im, rand(0, 100), rand(0, 100), rand(0, 100)); //Determine text size, and use dimensions to generate x & y coordinates $textsize = imagettfbbox($size, $angle, $font, $textstr); $twidth = abs($textsize[2]-$textsize[0]); $theight = abs($textsize[5]-$textsize[3]); $x = (imagesx($im)/2)-($twidth/2)+(rand(-20, 20)); $y = (imagesy($im))-($theight/2);//Add text to image ImageTTFText($im, $size, $angle, $x, $y, $color, $font, $textstr); //Output PNG Image header("Content-Type: image/png"); ImagePNG($im);//Destroy the image to free memory connect(); query("INSERT INTO security_images (insertdate, referenceid, hiddentext) VALUES ( now(), '".$referenceid."', '".$textstr."')"); //End output imagedestroy($im); exit; ?>

[/php]

As I said, this works perfectly fine on my localhost on my computer, but not online on my domain name. Any ideas?

Just a quick observation, did you upload the truetype font CENTAUR.ttf, and is it in your web root directory, and are the proper permissions applied?

Obvious, yes, but overlooked so often…

“GD is enabled on my web host and ‘functions.php’ exists in the same directory, as does the CENTAUR.TTF font file.”

Yes. I even reuploaded it to be double sure.

I’d still verify permissions…

Here’s another. What is the purpose for all this randomness in text size, color, angle and position. It’s hard to debug things when you introduce randomness. And frankly, it doesn’t make much sense. Your code creates a random string of 8 characters and places it over a graphic.

Pick an appropriate font, size, color, and angle and hard code into the script. Then dump all the calculations required to compensate for random size. Choose a high contrast color for your text.

Lastly you display the image but you do not save it. if you do save do not overwrite your base image file. Incorporate the 8 character code in the filename (which does not guaranty a unique file name - be careful). And FYI the comment after the code to display the image states it is to destroy the image, which is actually several lines down.

Okay first of all I’m not the one that coded this, I merely integrated it into my system. Second of all, it works, just on my localhost. The permissions are fine, I’ve checked everything basic like that and found nothing wrong with it. Doesn’t matter how stupid it looks, if it works, it works. And yeah the image destroy comment is out of place because I’ve been fiddling with the order of things to see if that made any difference. And I’m not saving the image directly, but it’s going as a row in my database, so it is being saved. I’ve seen it done this way a thousand times, I know how it works. The issue may not even be the code. What I’m wanting to know, is how something can work on my server, but not on my web host’s. Thank you for your input, but if you don’t know then please just let me wait for someone who does. Thanks.

Tried to find a way to modify my topic, couldn’t find one. Whatever the case I’ve taken the image part of the code down so users can register without it, I’d rather them be able to register at least. In the mean time I’ll try to keep finding out what’s wrong. Hopefully not something too complicated.

Gah, I’m really sorry for the extra post, I can’t find a modify topic button. DX

Anyway I’ve gotten things resolved for now, thanks anyway, thanks to anyone who even read it

First of all, if it works on you local box, doesn’t mean too much. Again, proper permissions on all files are important. Do not assume that uploading will preserve your permissions or apply the proper permissions. Set to 777 to cover all cases. Also your PHP, GD lib and Apache versions could be different than your local box. You may need to tinker with the php.ini file. I’m betting it doesn’t see the font, for whatever reason.

The image is not being save in your mysql database. Only the 8 character code. I’m guessing this image function is also used to display (recreate) the security badge after retrieving data from the server.

Lastly, no offense intended, but the random crap in that file really makes no sense and as I stated before can be hard to debug. Simplify this, then put back whatever randomness you please, but you must thoroughly test to insure a random combination does not produce undesirable effects. I’m wondering if the random options are creating circumstances that make it look as if it isn’t working and yet it is. Under certain font sizes, location, and angle, the text could be plotted completely outside the bounds of the graphic image. You have to work with knowns to debug, this randomness makes knowns, unknows… Try plotting the string ‘12345’ in a small size, black (or white if image is dark) from the left edge of the image. If you see your results, your on you way!

Look man, I don’t want any problems, alright? You seem to be kinda rude to people here and I don’t want no part of that. I’d rather hear from someone else. Either that or I can go somewhere else, don’t matter which. But lay off of me man, I ain’t hear to start trouble and I sure ain’t gonna egg you on about it.

Now please let someone else besides you answer because frankly you’re not helping a single bit at all.

Whoops.

here*

You beg for help and then refuse the help that’s offered. I said nothing offensive to you at all, so what’s your problem? Take my pervious recommendations, and prove me wrong…

Sponsor our Newsletter | Privacy Policy | Terms of Service