|
Posted by Co on March 4, 2009, 1:22 pm
Please log in for more thread options
Hi All,
I have a page for registering where I want to have a captcha.
I put the img on the form but he only thing I see is a black box
without any letters on it.
<?php
include("captcha.php");
if ($_SERVER['REQUEST_METHOD'] != "POST") // Controleren of er niet
ergens is gedrukt op een knop
{
// er is nergens op een knop gedrukt, maar gewoon handmatig
gerefreshed..
$_SESSION['code'] = ""; // de $_SESSION['code'] leeg gooien
$code = code_generator(rand (4,5)); // een nieuwe key maken
}
if (empty ($_SESSION['code'])) // controleren of de sessie leeg is
{
// de sessie is leeg, de code toewijzen aan de sessie
$_SESSION['code'] = $code;
}
captcha_generator ($_SESSION['code']); // het genereren van de image
echo "
show/hide quoted text
<HTML>
<HEAD>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #000000;
text-decoration: none;
scrollbar-face-color: #DEE3E7;
scrollbar-highlight-color: #FFFFFF;
scrollbar-shadow-color: #DEE3E7;
scrollbar-3dlight-color: #D1D7DC;
scrollbar-arrow-color: #006699;
scrollbar-track-color: #EFEFEF;
scrollbar-darkshadow-color: #98AAB1;
background-color: #FFFFFF;
margin: 0px;
}
td {
font-size: 10px;
color: #666666;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
border-bottom-style:none;
}
tr {
font-size: 10px;
color: #666666;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
border-bottom-style:none;
}
th {
font-size: 10px;
color: #666666;
font-family: Verdana, Arial, Helvetica, sans-serif;
text-decoration: none;
border-bottom-style:none;
border:0;
}
A {text-decoration: none;COLOR: #000000; }
A:visited { text-decoration: none;color: #000000; }
A:hover { COLOR: #000000; TEXT-DECORATION: none }
.style1 {
font color:#000000;
}
.style2 {
font color: #000000;
}
.style3 {
font color: #ffffff;
}
form {
font-family: Tahoma, Arial, Helvetica, sans-serif;
font-size: 11px;
color: #ffffff;}
body {
color: #000000;
}
.tablest { text-decoration: none;
border-color: #000000;
background :#D8D8D8;
}
.tablebg1 { text-decoration: none;
border-color: #000000;
background :#59002D;
}
.tablebg2 { font-family: Tahoma, Arial,
Helvetica, sans-serif;
font-size: 11px;
text-decoration: none;
border-color: #000000;
font-color : #ffffff;
color : #ffffff;
background :#010D55;
}
.tablebg3{ background :#CCCCCC;
border-color :
#cccccc;
}
.tablebg4{
background :#F4F4F4;
color : #000000;
font-color : #ffffff;
}
.tablebg5{
border-color: #000000;
color : #000000;
}
.adminarea{ font-family: arial;
font-size: 30px;
font-style:oblique;
text-decoration: none;
border-color: #000000;
font-color : #ffffff;
color : #ffffff;
background :#010D55;
font-weight: bold;
}
.textboxgray {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #666666;
border: 1px solid #999999;
background-color: #f7f7f7;
}
.textboxgray1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #666666;
border: 1px solid #999999;
background-color: #f7f7f7;
padding: 1px;
width:100%;
border-spacing: inherit;
}
form {
margin: 0px;
padding: 20px;
color: #000000;
}
show/hide quoted text
</STYLE>
</HEAD>
<body>
<form name=form1 method=post action=register2.php>
<center>
<br><br>
<table width=410 border=1 cellpadding=4 cellspacing=0>
<tr>
<td width=410 align=left valign=top bgcolor=#F0F0F0>
<table width=400 border=0 cellpadding=4 cellspacing=0>
<tr>
<td width=54% align=left valign=top>Voornaam</td>
<td width=46%><input name=first_name type=text id=first_name> *</
td>
</tr>
<tr>
<td align=left valign=top>Achternaam</td>
<td><input name=last_name type=text id=last_name> *</td>
</tr>
<tr>
<td align=left valign=top>E-mail adres</td>
<td><input name=email_address type=text id=email_address> *</td>
</tr>
<tr>
<td align=left valign=top>Gewenste Username</td>
<td><input name=username type=text id=username> *</td>
</tr>
<tr>
<td align=left valign=top>Informatie over jou</td>
<td><textarea name=info id=info></textarea></td></tr>
<tr>
<tr><br>
<td align=left valign=top>Ontvang <strong>Gratis</strong> SMS
bij Nieuws.</td>
<td><input type=checkbox name=sms value='ja'></td></tr>
<tr>
<tr>
<td align=left valign=top>Mobiel nummer</td>
<td><input name=gsm type=text id=gsm><br>(Format +31612345678)</
td></tr>
<tr>
<td align=left valign=top> </td>
<td><input type=submit name=Submit value=Join Now!></td>
</tr>
</table>
</table><br>
Velden gemarkeerd met een asterisk (*) zijn verplicht.
show/hide quoted text
</form>
</center>
</body>
</html>
";
show/hide quoted text
echo "<img src=captcha2.png alt=''>";
?>
<HTML>
<HEAD>
</HEAD>
----------------------| Captcha.php
|------------------------------------------------
<?PHP
//error_reporting (E_ALL); // fouten weergeven
function code_generator($length)
{
$generated_key = "";
while (strlen($generated_key) < $length)
{
$generate = mt_rand(48, 90);
show/hide quoted text
if ($generate < 58 || $generate > 64) $generated_key .=
strtolower(chr($generate));
}
return $generated_key;
}
function captcha_generator($code)
{
//$code = code_generator(5); // even een testcode aanmaken, zie
paragraaf 5 voor een voorbeeld keygen.
$image = imagecreatetruecolor (200, 40); // maakt de image met de
groote van 300px breed, en 60px hoog
$aFonts = array ('Yiggivoo1.ttf', 'duepuntozero.ttf',
'bertoltbrecht.ttf', 'phrixus.ttf'); // zet alle beschikbare fonts in
een array
$aCode = str_split ($code); // zet alle karakters apart in een array
for ($i = 0; $i < count ($aCode); $i++) // een for-lus maken voor het
aantal karakters dat de $aCode array bevat
{
$fontcolor = imagecolorallocate ($image, // kleurencombinatie maken
voor de image variabel ($image)
rand (190, 255), // rood,
rand (190, 255), // groen,
rand (190, 255)); // blauw, deze geven de nieuwe kleur per
karakter
if (count ($aCode) == 4) // de volgende locaties (x-as) aanmaken
voor een code van 4 karakters lang
{
$pos[0] = rand (15, 55); // locatie aanmaken (x-as) voor de
eerste karakter
$pos[1] = rand (80, 120); // locatie aanmaken (x-as) voor de
tweede karakter
$pos[2] = rand (145, 185); // locatie aanmaken (x-as) voor de
derde karakter
$pos[3] = rand (210, 250); // locatie aanmaken (x-as) voor de
vierde karakter
}
if (count ($aCode) == 5) // de volgende locaties (x-as) aanmaken
voor een code van 5 karakters lang
{
$pos[0] = rand (10, 45); // locatie aanmaken (x-as) voor de
eerste karakter
$pos[1] = rand (65, 100); // locatie aanmaken (x-as) voor de
tweede karakter
$pos[2] = rand (120, 155); // locatie aanmaken (x-as) voor de
derde karakter
$pos[3] = rand (175, 210); // locatie aanmaken (x-as) voor de
vierde karakter
$pos[4] = rand (230, 265); // locatie aanmaken (x-as) voor de
vijfde karakter
}
imagettftext ($image, // image voorbereiden voor de image variabel
($image)
rand (16, 20), // fontgrootte, willekeurig getal laten kiezen
tussen de 13 en 19
rand (-30, 30), // draaihoek, willekeur getal laten kiezen tussen
de -31 en de 31
$pos[$i], // karakter positie breedte toewijzen, hebben we al
voorbereid ($pos[])
rand (50, 20), // karakter positie hoogte, kiezen tussen de 51 en
de 19
$fontcolor, // fontkleur toewijzen, hebben we al voorbereid
($fontcolor)
$aFonts[rand (0, 3)], // font, willekeurig font toewijzen uit de
array ($aFonts)
$aCode[$i]); // code toewijzen, op volgorde van de array
}
imagepng ($image, 'captcha2.png'); // de .png image aanmaken als
captcha.png
imagedestroy ($image); // de handel afronden, en klaar!
}
show/hide quoted text
?>
Marco
|
|
Posted by Jerry Stuckle on March 4, 2009, 2:02 pm
Please log in for more thread options
Co wrote:
show/hide quoted text
> Hi All,
>
> I have a page for registering where I want to have a captcha.
> I put the img on the form but he only thing I see is a black box
> without any letters on it.
>
<lots of code snipped>
>
> Marco
Why don't you ask the developer of the CAPTCHA code? He's more familiar
with it than anyone
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
|
|
Posted by David Barnes on March 4, 2009, 3:48 pm
Please log in for more thread options show/hide quoted text
> Hi All,
> I have a page for registering where I want to have a captcha.
> I put the img on the form but he only thing I see is a black box
> without any letters on it.
> Marco
Hi Marco,
Perhaps your font files are not there. When I first ran this script I
got this error:
Warning: imagettftext() [function.imagettftext]: Could not find/open
font in /usr/local/www/apache22/data/missilesilo/david/Captcha.php on
line 53
I copied arial.ttf into the same directory that I ran the script from,
and I changed $aFonts:
$aFonts =3D array('arial.ttf','arial.ttf','arial.ttf','arial.ttf');
I now see colored letters instead of a black box. Hope this helps.
-David
|
|
Posted by Co on March 5, 2009, 2:32 am
Please log in for more thread options show/hide quoted text
> > Hi All,
> > I have a page for registering where I want to have a captcha.
> > I put the img on the form but he only thing I see is a black box
> > without any letters on it.
> > Marco
> Hi Marco,
> Perhaps your font files are not there. When I first ran this script I
> got this error:
> Warning: imagettftext() [function.imagettftext]: Could not find/open
> font in /usr/local/www/apache22/data/missilesilo/david/Captcha.php on
> line 53
> I copied arial.ttf into the same directory that I ran the script from,
> and I changed $aFonts:
> $aFonts =3D array('arial.ttf','arial.ttf','arial.ttf','arial.ttf');
> I now see colored letters instead of a black box. Hope this helps.
> -David
David,
The problem is not really the captcha code because I can also see the
image when I run it as a seperate php form.
However in my form as posted I can only see a black screen with no
letters.
Marco
|
|
Posted by Bill H on March 5, 2009, 5:44 am
Please log in for more thread options show/hide quoted text
> > > Hi All,
> > > I have a page for registering where I want to have a captcha.
> > > I put the img on the form but he only thing I see is a black box
> > > without any letters on it.
> > > Marco
> > Hi Marco,
> > Perhaps your font files are not there. When I first ran this script I
> > got this error:
> > Warning: imagettftext() [function.imagettftext]: Could not find/open
> > font in /usr/local/www/apache22/data/missilesilo/david/Captcha.php on
> > line 53
> > I copied arial.ttf into the same directory that I ran the script from,
> > and I changed $aFonts:
> > $aFonts =3D array('arial.ttf','arial.ttf','arial.ttf','arial.ttf');
> > I now see colored letters instead of a black box. Hope this helps.
> > -David
> David,
> The problem is not really the captcha code because I can also see the
> image when I run it as a seperate php form.
> However in my form as posted I can only see a black screen with no
> letters.
> Marco- Hide quoted text -
> - Show quoted text -
Marco
completely not php, remove this:
body {
color: #000000;
}
from your code and it will not be a black screen
Bill H
|
| Similar Threads | Posted | | Poor man's captcha: why wouldn't this work? | September 19, 2006, 8:27 pm |
| What captcha script(s) do you like? | July 15, 2008, 5:31 pm |
| httpclient with captcha | October 31, 2008, 3:42 pm |
| Generating captcha | November 23, 2008, 8:44 pm |
| OT: (sortof) Captcha? | January 21, 2009, 9:46 pm |
| captcha - do you know such solution? | February 21, 2010, 3:01 pm |
| Any good CAPTCHA to recommend? | June 14, 2006, 7:16 pm |
| Formmail + Captcha Verification | September 14, 2007, 10:26 am |
| session start and captcha... | March 8, 2009, 5:15 am |
| session start and captcha... | March 8, 2009, 5:11 am |
|
<HEAD>
<style>