Click to See Complete Forum and Search --> : Contact form and verfications with image where are numbers


toplisek
11-28-2005, 07:42 AM
I have read articles about this and have the following code, which shows me error
The image “http://www....imageVer.php” cannot be displayed, because it contains errors.



I have received some answer that the script is looking for an image in that directory which it cannot find. Wht can be wrong?


Code is the following


<?php

session_start();

/*header*/
Header("Content-Type: image/png");

/* initialize a session. */
//session_start();

/*We'll set this variable later.*/
$new_string;

/*register the session variable. */
session_register('new_string');

/*You will need these two lines below.*/
echo "<html><head><title>Verification</title></head>";
echo "<body>";

/* set up image, the first number is the width and the second is the
height*/
$im = ImageCreate(200, 40);

/*creates two variables to store color*/
$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);

/*random string generator.*/
/*The seed for the random number*/
srand((double)microtime()*1000000);

/*Runs the string through the md5 function*/
$string = md5(rand(0,9999));

/*creates the new string. */
$new_string = substr($string, 17, 5);

/*fill image with black*/
ImageFill($im, 0, 0, $black);

/*writes string */
ImageString($im, 4, 96, 19, $new_string, $white);

/* output to browser*/
ImagePNG($im, "verify.png");
ImageDestroy($im);

/*I plugged our image in like I would any other image.*/
echo "<img src=\"verify.png\">";
echo "<br><br>";
echo "Type the code you see in the image in the box below. (case
sensitive)";
echo " <form action=\"formhandler.php\" method=post>";
echo "<input name=\"random\" type=\"text\" value=\"\">";
echo "<input type=\"submit\">";
echo "</form>";
echo "</body>";
echo "</html>";
?>

SpectreReturns
11-29-2005, 12:07 AM
I wish they would fix that bug in phpBB where it doesn't populate links propperly.

Anyway, that isn't the problem. The problem is that GD is creating your image invalidly, which is why it gives you errors.

toplisek
11-30-2005, 05:53 AM
so, if I understand the problem is in Hosting Provider?

bokeh
11-30-2005, 06:01 AM
so, if I understand the problem is in Hosting Provider?No, the fault is with your code. You need to make up your mind if you are sending an image or an html file. Your code sends half of each. First it outputs a PNG header, then a block of html, then you build a PNG file then, you output another block of html. No wonder the browser doesn't understand.

If you are sending html it needs an html header. Also your script is very stupid from the point of view of saving the image to file rather than sending it to the browser. There is no sure way to know the correct person will get the correct image because there could be a cross over in file requests.$new_string;
$new_string = substr($string, 17, 5);YOU STILL AREN'T LISTENING SO I WILL WRITE THIS AGAIN EXTRA BIG JUST FOR YOU! NAME YOUR VARIABLES WITH PROPER NAMES SO IT IS EASIER FOR PEOPLE TRYING TO HELP YOU! Here is an example:$string_contains_rand_number_between_0_and_9999 = md5(rand(0,9999));
$substring_17_5_of_ string_that_contains_rand_number_between_0_and_9999= substr($string_contains_rand_number_between_0_and_9999, 17, 5);Now if you look at that careful don't you see the another fault in your script? How can you have a substring_17_5 when the source string contains a maximum of four characters. Now do you see how important it is to give variables proper names? srand((double)microtime()*1000000);What is that? How is it connected to your script? All it seems to be doing is wasting CPU cycles.

toplisek
11-30-2005, 08:34 AM
Before you write angry letters, please look at web site that I found this script. It is not from me!

Please send all angry word to Darryl Porter:
Article: An Image Verification Tutorial
http://www.devpapers.com/article/149

bokeh
11-30-2005, 10:02 AM
Before you write angry letters, please look at web site that I found this script. It is not from me!

Please send all angry word to Darryl Porter:
Article: An Image Verification Tutorial
http://www.devpapers.com/article/149Toplisek, just steer well clear of that script. It will never work. I can't believe someone that writes such poor code is also writing tutorials...

If you must have a captcha image in your form there is one available in my signature.

toplisek
11-30-2005, 02:45 PM
Thanks,
I will look. thanks.

I have trusted this code. But actually not paid very much attention to code. Sorry.

Thanks a lot for help.

SpectreReturns
12-01-2005, 01:05 AM
Oops, I didn't read the whole script correctly.
/*You will need these two lines below.*/
echo "<html><head><title>Verification</title></head>";
echo "<body>"; That's going to kill any image rendering you want to do.

Sheldon
12-01-2005, 04:01 AM
Thanks,
I will look. thanks.

I have trusted this code. But actually not paid very much attention to code. Sorry.

Thanks a lot for help.

How cn uoy trust a code you have found randomally on the net nad then post it here with ut giving us a decent error and yet ands i quote

"actually not paid very much attention to code"???


Are you purposly trying to waste our time?

toplisek
12-01-2005, 05:32 AM
this code is not randomly as Darryl Porter is well known. I need script as I quoted.
Bokeh sent me one link.

bokeh
12-01-2005, 07:05 AM
Darryl Porter is well known.Toplisek, the code in that tutorial sucks, but, if you want to be one of Darryl Porter's disciples and follow him over his metaphorical cliff like a sheep that is your prerogative.

toplisek
03-26-2006, 05:53 AM
Dear Bokeh,
I test your code for Captcha.

Can you tell me what to do that it will work? It gives me error:
Warning: main(.../captcha/captcha_demo.php): failed to open stream: No such file or directory in .../Captcha/captcha_demo.php on line 5

Line 5 is :require_once(CAPTCHA_PATH.'captcha_demo.php');

bokeh
03-26-2006, 06:18 AM
Can you tell me what to do that it will work? Yes, follow the instructions in the readme doc. If you find that too difficult use the following script instead:<?php

session_start();

if(isset($_GET['i'])){
// image creation section
captcha_image();
}elseif(isset($_POST['captcha'])){
// validation section
echo(captcha_validate())?'That was correct.<br>':'That was not correct.<br>';
echo '<a href="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'">Try another?</a>';
exit;

}else{
// form section
echo
'<img src="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?i='.uniqid().'" alt=""><br>'."\n".
'<form action="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'" method="POST">'."\n".
'<input type="text" name="captcha" ><input type="submit" value="test it"></form>';

}

function captcha_validate()
{
if($_POST['captcha'] == $_SESSION['captcha'])
{
$_SESSION['captcha'] = NULL;
return TRUE;
}
return FALSE;
}

function captcha_image()
{
$_SESSION['captcha'] = substr(uniqid(), 0, 8);
$image = imagecreate(80, 20);
$background_colour = imagecolorallocate($image, 255,255,255);
$text_shadow = imagecolorallocate($image, 127,127,127);
$text_colour = imagecolorallocate($image, 0,0,0);
imagestring($image, 5, 1, 1, $_SESSION['captcha'], $text_shadow);
imagestring($image, 5, 0, 0, $_SESSION['captcha'], $text_colour);
header ('Content-type: image/png');
imagepng($image, null, 100);
imagedestroy($image);
exit;
}

?>

toplisek
03-26-2006, 10:12 AM
Bokeh,
Need help with your basic code.

Your code in Read Me file is:


<?php
session_start();
define('CAPTCHA_PATH', $_SERVER['DOCUMENT_ROOT'].'/capcha/');
require_once(CAPTCHA_PATH. .php');



Sorry but I'm new to function define. I just noticed that there is probably mistake in require_once(CAPTCHA_PATH. .php');

Please advise me how to do your basic code? I'm new to define function.

Regarding second code, it gives me error and actually do not know what is wrong. Error is:

Warning: uniqid() expects at least 1 parameter, 0 given in .../captcha_demo2.php on line 17
Line 17 is:
'<img src="http://mywebsite/captcha/'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?i='.uniqid().'" alt=""><br>'."\n".

bokeh
03-26-2006, 11:59 AM
your Read me file has full of mistakes. Really? Can you point them out to me? You are the first person to have suggested such a thing. Everyone else has said how simple they found it.

toplisek
03-26-2006, 01:42 PM
Hi Bokeh,
this is not fair for your code that is full of mistakes. So, I erased this quote.

You are the best as Sheldon.

Let us start with first problem. I have read all your Read Me file. :)

I have code for define:

session_start();
define('CAPTCHA_PATH', $_SERVER['DOCUMENT_ROOT'].'/captcha/'); // Path to captcha
require_once(CAPTCHA_PATH.'captcha.php');


What should be here that it will recognise file captcha_demo.php
I have put all files in directory testing directory Captcha/ and all 15 images in sub-directory /captcha/
So, path is /Captcha/captcha

Error is the following:
Warning: main(...captcha/captcha.php): failed to open stream: No such file or directory in .../Captcha/captcha_demo.php on line 6

Fatal error: main(): Failed opening required '.../captcha/captcha.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in .../Captcha/captcha_demo.php on line 6

Line 6 is:
require_once(CAPTCHA_PATH.'captcha.php');

bokeh
03-26-2006, 02:45 PM
I don't have any idea hat you are talking about except that you haven't followed the instructions. Put the directory "captcha" in you root directory and put tha demo file anywhere you choose. Mopdify nothing.

toplisek
03-27-2006, 01:55 AM
Now it works.

Need help by image.
- I have background image and would like to show image which I will decide. How to do it?
- you have written: put 5-10 .ttf files in the 'captcha' directory
Can I put just fonts or it can be GIF images e.g. 1.gif, 2.gif that it will be size of fonts defined e.g. height:18x14 (width) and numbers with words will be all the time Big characters not mixed.

bokeh
03-27-2006, 04:19 AM
Now it works. It would have worked immediately if you had followed the instructions to start with.I have background image and would like to show image which I will decide. How to do it?You would need to rewrite the function that builds the image.you have written: put 5-10 .ttf files in the 'captcha' directory... Can I put just fonts or it can be GIF imagesFont files! GIF images are not font files!

Toplisek, There was a demonstration of the script on the site. If you were not happy with the demonstration why did you bother to download the script?

If you want a custom script you will either need to write your own or pay someone to write it for you.

toplisek
03-27-2006, 04:29 AM
There was a demonstration of the script on the site. If you were not happy with the demonstration why did you bother to download the script?
.

1. Question: I have seen that there are some background images and do not know if I can put my image.

2. Question: Can I enlarge size of fonts?

bokeh
03-27-2006, 04:39 AM
1. Question: I have seen that there are some background images and do not know if I can put my image.There is no background image. The whole image is being built with GD.
2. Question: Can I enlarge size of fonts?The font is already pretty big, why would you want to make it bigger? Changing the font size would entail completely rewriting the function since a bigger font would place some of the text string outside the image dimmensions.

toplisek
03-27-2006, 06:03 AM
I have tested from web site : http://www.ejeliot.com/

It is very good and has all function which I need.

bokeh
03-27-2006, 06:26 AM
I have tested from web site : http://www.ejeliot.com/

It is very good and has all function which I need.The difference between my captcha and that one is:

1) My captcha image is pleasing to the eye,

and

2) It runs on PHP without any additional installs. The captcha you have linked to needs the flite audio software program (written in C) and which will need to be installed on your server; hardly a PHP solution.

If it suits your needs good luck with it. I'm sure it will be a delight for the scriptwriter to answer the barrage of idiotic questions he's sure to receive.

toplisek
03-27-2006, 07:12 AM
No comment.