View Full Version : Verification
igloo01
March 26th, 2006, 01:01 PM
I have put a verification page onto my site, before you can get onto the guestbook. This seemed to be working fine in Internet Explorer, but when I tried to open it in Firefox, it says
"The image “http://members.lycos.co.uk/londoneye/gbook/verify.php” cannot be displayed, because it contains errors."
Here's the address to the guestbook (http://guest.the-london-eye.com).
I used a pre-made verification codewhich I edited a bit to fit my site.
Would be good if someone could have a look to see what's wrong.
Thanks!
degsy
March 26th, 2006, 02:27 PM
Where did you get the script?
igloo01
March 26th, 2006, 02:54 PM
http://www.phpnoise.com/tutorials/1/1
I just went through what they said...then edited it!
degsy
March 26th, 2006, 02:57 PM
What is your current code?
igloo01
March 26th, 2006, 06:34 PM
This is the first part - the page you are taken to to enter the code:
The administrator part takes you to a different page if you enter the correct password (by adding that password onto the end of the address)
<?php
/*header*/
Header("Content-Type: image/png");
/* initialize a session. */
session_start();
session_unset();
ImageDestroy(verify.png);
/*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>Guestbook Verification</title></head>";
echo '<body bgcolor="#D3D3D3" text="#000000" link="#0000FF" vlink="#FF0000">';
/* 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 "Please type the code you see in the image in the box below. (case sensitive)";
echo " <form action=\"guestbook.php\" method=post>";
echo "<input name=\"random\" type=\"text\" value=\"\">";
echo "<input type=\"submit\">";
/*Administrator enters password here*/
echo "<p>";
echo"Administrator only:";
echo "<input name=\"random2\" type=\"password\" value=\"\">";
echo "</form>";
echo "</body>";
echo "</html>";
?>
I'll post the next bit below.
igloo01
March 26th, 2006, 06:37 PM
this is on the actual guestbook page:
<?php
/*This starts the session that we created on the last page*/
session_start();
session_register('random');
/*This trims the random variable of any white space that the user may have unknowingly put in.*/
$random=trim($random);
/*If no image has been created, treat it as if they are not verified*/
if($new_string == ""){
echo "<html>\n";
echo "<head>\n";
echo "<title>London Eye Guestbook Verification Missed</title>\n";
echo "</head>\n";
echo '<body bgcolor="#D3D3D3" text="#000000" link="#0000FF" vlink="#FF0000">';
echo '<img src="http://members.lycos.co.uk/londoneye/pict/own_logo.jpg">';
echo '<p>Please <a href="http://guest.the-london-eye.com">go back</a> and get verified';
echo '<p>If you are having problems with this page, please <a href="mailto:design@the-london-eye.com">email</a> the designers. Thank you';
echo '<p align="right">No string created</p>';
echo "</body>\n";
echo "</html>\n";
}
/*This checks if the administrator password has been entered and, if it has, takes you to the admin page - only if the password is right*/
elseif($random2 <> ""){
echo"<a href=\"guestbook.php?admin=$random2\">Admin</a>\n";
}
/*We can use the variable $new_string because we registered it into our session on the last page, it retains its value that it had on the first page.*/
elseif ($new_string == $random){
PAGE CODE
}
else{
echo "<html>\n";
echo "<head>\n";
echo "<title>London Eye Guestbook Verification Failed</title>\n";
echo "</head>\n";
echo '<body bgcolor="#D3D3D3" text="#000000" link="#0000FF" vlink="#FF0000">';
echo '<img src="http://members.lycos.co.uk/londoneye/pict/own_logo.jpg">';
echo '<p>Please <a href="http://guest.the-london-eye.com">go back</a> and get verified';
echo '<p>If you are having problems with this page, please <a href="mailto:design@the-london-eye.com">email</a> the designers. Thank you';
echo '<p align="right">Wrong String</p>';
echo "</body>\n";
echo "</html>\n";
}
?>
degsy
March 26th, 2006, 07:00 PM
You have several errors. Remember that PHP is case sensitive.
e.g.
Header should be header
ImageDestroy should be imagedestroy
ImageCreate should be imagecreate
Here is a list of some of the functions
http://uk2.php.net/manual/en/ref.image.php
degsy
March 26th, 2006, 08:08 PM
Your main problem is this
Header("Content-Type: image/png");
You are telling the browser that it is loading an image, but you are also outputting HTML.
Either put the image code into it's own file or remove the header.
igloo01
March 26th, 2006, 08:12 PM
I do not know how to put the image code into it's own file, so I just removed the header! It seems to be working now :)
If you could just help me with the final problem, that would be great: If you type in the code incorrectly, you are taken to a new page and asked to try again. When you go back to the code entry page, the old code you have to type in is still displayed, but it creates a new code to check this with. So, when you type in the code you see it is wrong. You have to manually refresh the page to get the new code shown.
Here is the code I used to try and get the image to refresh (everything I could find!)
/* initialize a session. */
session_start();
session_unset();
imagedestroy(verify.png);
Thanks
degsy
March 26th, 2006, 09:43 PM
You could try an expiration header, but i'm not sure that will work.
I would recommend that you combine the scripts so that it is in one page. That way you will always have a page refresh and a correct code.
igloo01
March 27th, 2006, 10:16 AM
I thought about that, but how can I get the page to "stop" after the form, then continue through the page after they have entered the code?
Also, what happens if they click on a link, like next page - it would then have to go through the code part, wouldn't it?
Thanks
degsy
March 27th, 2006, 10:48 AM
There are different methods. One is to chage the location of your error message.
elseif ($new_string == $random){
PAGE CODE
}
else{
echo "<html>\n";
echo "<head>\n";
echo "<title>London Eye Guestbook Verification Failed</title>\n";
echo "</head>\n";
echo '<body bgcolor="#D3D3D3" text="#000000" link="#0000FF" vlink="#FF0000">';
echo '<img src="http://members.lycos.co.uk/londoneye/pict/own_logo.jpg">';
echo '<p>Please <a href="http://guest.the-london-eye.com">go back</a> and get verified';
echo '<p>If you are having problems with this page, please <a href="mailto:design@the-london-eye.com">email</a> the designers. Thank you';
echo '<p align="right">Wrong String</p>';
echo "</body>\n";
echo "</html>\n";
}
?>
elseif ($new_string == $random){
PAGE CODE
}
else{
header("Location: verify.php?wrongstring=1")}
?>
/*I plugged our image in like I would any other image.*/
echo "<img src=\"verify.png\">";
echo "<br><br>";
if(isset($_GET['wrongstring'])){
echo "<strong>Wrong code entered</strong><br>";
}
echo "Please type the code you see in the image in the box below. (case sensitive)";
igloo01
March 27th, 2006, 12:54 PM
not sure if I've done what you said correctly - the guestbook now comes up with an error:
"Parse error: parse error in /data/members/free/tripod/uk/l/o/n/londoneye/htdocs/gbook/guestbook.php on line 645" This is in the page code...as far as I can see it is:
if (empty($pperpage)) $pperpage = 9; //!!! ONLY 5,7,9,11,13 !!!!
From what I can see, i need to replace the 2 bits of code with the code you have given me. From my limited knowledge, I think if this takes the user back to the verify page, if they enter the code incorrectly. The page sees that they have got the code wrong and says the code entered is incorrect and they have to enter it again.
Is this all meant to be on one page, or do I keep the same pages as before.
Sorry - a bit confused!
igloo01
March 27th, 2006, 12:59 PM
by the way, thanks for all your help so far - I do appreciate everything.
degsy
March 27th, 2006, 01:03 PM
Typo
Replace
header("Location: verify.php?wrongstring=1")}
With
header("Location: verify.php?wrongstring=1");
}
igloo01
March 27th, 2006, 01:38 PM
ah yes - sorry, should have spotted that myself.
All seems to be working now, just as I asked for - thanks...again!!
Igloo
degsy
March 27th, 2006, 03:12 PM
No probs :)