von Jago » 26.06.2007, 09:24
Hi Frameguard!
Das ist aber nett von Dir zu hören. Deshalb Hier der Code, wie Du Ihn willst:
Ich habe im Hauptverzeichnes 2. Seiten.
Die 1. mit Namen"capchaform.htm" und dies steht drinnen:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
<title>Kontaktformular</title>
</head>
<body bgcolor=#B3B3FF Link=#0000FF ALink=#FF0000 VLink=#808080 >
<style type="text/css"> <!--
.PS_1{
top:339px;
width:100px;
height:30px;
border-width:1px;
font-size:8pt;
border-color:#000000;
color:#000000;
background-color:#9393FF;
border-style:solid;
font-weight:;
font-family:Arial;
cursor:pointer;
font-style:;
}
.PC_1{
top:339px;
width:100px;
height:30px;
border-width:1px;
font-size:8pt;
border-color:#808080;
color:#808080;
background-color:#9393FF;
border-style:solid;
font-weight:;
font-family:Arial;
cursor:pointer;
font-style:;
}
.TED1_1{
top:10px;
width:288px;
height:24px;
border-width:0px;
font-size:13pt;
border-color:#000000;
color:#FFFFFF;
background-color:#B3B3FF;
border-style:none;
font-weight:bold;
font-family:Tahoma;
cursor:text;
font-style:;
}
.TED2_1{
top:90px;
width:250px;
height:20px;
border-width:1px;
font-size:10pt;
border-color:#000000;
color:#0000A0;
background-color:#FFFFFF;
border-style:solid;
font-weight:;
font-family:Tahoma;
cursor:text;
font-style:;
}
.TED3_1{
top:120px;
width:250px;
height:20px;
border-width:1px;
font-size:10pt;
border-color:#000000;
color:#0000A0;
background-color:#FFFFFF;
border-style:solid;
font-weight:;
font-family:Tahoma;
cursor:text;
font-style:;
}
.TME4_1{
top:219px;
width:370px;
height:100px;
border-width:1px;
font-size:10pt;
border-color:#000000;
color:#0000A0;
background-color:#FFFFFF;
border-style:solid;
font-weight:;
font-family:Tahoma;
cursor:text;
font-style:;
}
.TTE5_1{
top:87px;
width:110px;
height:20px;
border-width:0px;
font-size:10pt;
border-color:#C0C0C0;
color:#400080;
background-color:#B3B3FF;
border-style:none;
font-weight:bold;
font-family:Tahoma;
cursor:text;
font-style:;
}
.TTE6_1{
top:119px;
width:108px;
height:18px;
border-width:0px;
font-size:10pt;
border-color:#C0C0C0;
color:#400080;
background-color:#B3B3FF;
border-style:none;
font-weight:bold;
font-family:Tahoma;
cursor:text;
font-style:;
}
.TTE7_1{
top:148px;
width:110px;
height:20px;
border-width:0px;
font-size:10pt;
border-color:#C0C0C0;
color:#400080;
background-color:#B3B3FF;
border-style:none;
font-weight:bold;
font-family:Tahoma;
cursor:text;
font-style:;
}
.TTE8_1{
top:194px;
width:108px;
height:18px;
border-width:0px;
font-size:10pt;
border-color:#C0C0C0;
color:#400080;
background-color:#B3B3FF;
border-style:none;
font-weight:bold;
font-family:Tahoma;
cursor:text;
font-style:;
}
.TED9_1{
top:150px;
width:250px;
height:20px;
border-width:1px;
font-size:10pt;
border-color:#000000;
color:#0000A0;
background-color:#FFFFFF;
border-style:solid;
font-weight:;
font-family:Tahoma;
cursor:text;
font-style:;
}
.TSE10_1{
top:60px;
width:110px;
height:24px;
border-width:0px;
font-size:10pt;
border-color:#000000;
color:#400080;
background-color:#FFFFFF;
border-style:none;
font-weight:;
font-family:Tahoma;
cursor:text;
font-style:;
}
p.captcha{
top : 400px;
left : 100px;
position : absolute;
font-size:10pt;
font-family:Tahoma;
color:#400080;
}
p.p01{
position:absolute;
z-index: 3;
top:10px;
left : 55px;
font-family : Arial, Helvetica, sans-serif;
font-size : 15px;
color : #EFEFF8;
font-weight : bold;
}
-->
</style>
<script language=javascript>
function check_form()
{
var error,i,set,str,ele,elenam,zeichen;
ele=2;
elenam='Vorname';
set='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZß 1234567890öäüÖÄÜ';
str=window.document.forms[0].elements[ele].value;
for (i=0;i<=str.length;i++)
{
zeichen=str.charAt(i);
if (set.indexOf(zeichen)==-1)
{
alert('In Element '+elenam+' bitte nur Buchstaben oder Ziffern eingeben');
return false;
i=str.length;
}
}
ele=3;
elenam='Name';
set='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZß 1234567890öäüÖÄÜ';
str=window.document.forms[0].elements[ele].value;
for (i=0;i<=str.length;i++)
{
zeichen=str.charAt(i);
if (set.indexOf(zeichen)==-1)
{
alert('In Element '+elenam+' bitte nur Buchstaben oder Ziffern eingeben');
return false;
i=str.length;
}
}
ele=4;
elenam='mail';
str=window.document.forms[0].elements[ele].value;
if (str.indexOf('@',0)==-1)
{
alert('Ungültige E-Mailadresse in Feld: '+elenam);
return false;
}
if (str.length<6)
{
alert('Ungültige E-Mailadresse in Feld: '+elenam);
return false;
}
ele=1;
elenam='Anrede';
str=window.document.forms[0].elements[ele].selectedIndex;
if (str==0)
{
alert('Bitte wählen Sie im Feld '+elenam+' einen Eintrag aus!');
return false;
}
}
</script>
<form action=captchapruef.php method=post>
<input type=hidden name=ToMail value=manfred@digitcon.de>
<p class="p01">Was möchten Sie wissen ?</p>
<DIV ID=EL1 style="position:absolute; left:179px;top:60px;z-index:12">
<select class=TSE10_1 name=Anrede>
<option>--- Anrede ---</option>
<option>Frau</option>
<option>Herr</option>
<option>Dr.</option>
<option>Prof.</option>
<option>Prof. Dr.</option>
<option>Mrs.</option>
<option>Mr.</option>
</select>
</DIV>
<DIV ID=EL2 style="position:absolute; left:57px;top:87px;z-index:7">
<font class=TTE5_1> Vorname</font>
</DIV>
<DIV ID=EL3 style="position:absolute; left:180px;top:90px;z-index:4">
<input class=TED2_1 type=text name=Vorname value=>
</DIV>
<DIV ID=EL4 style="position:absolute; left:59px;top:119px;z-index:8">
<font class=TTE6_1> Name</font>
</DIV>
<DIV ID=EL5 style="position:absolute; left:180px;top:120px;z-index:5">
<input class=TED3_1 type=text name=Name value=>
</DIV>
<DIV ID=EL6 style="position:absolute; left:58px;top:148px;z-index:9">
<font class=TTE7_1> e-Mail</font>
</DIV>
<DIV ID=EL7 style="position:absolute; left:180px;top:150px;z-index:11">
<input class=TED9_1 type=text name=mail value=>
</DIV>
<DIV ID=EL8 style="position:absolute; left:65px;top:194px;z-index:10">
<font class=TTE8_1>Ihre Nachricht :</font>
</DIV>
<DIV ID=EL9 style="position:absolute; left:59px;top:219px;z-index:6">
<textarea class=TME4_1 name=info></textarea>
</DIV>
<DIV ID=EL10 style="position:absolute; left:59px;top:339px;z-index:1">
<input class=PS_1 type=Submit value=Senden onclick="return check_form()">
</DIV>
<DIV ID=EL11 style="position:absolute; left:169px;top:339px;z-index:2">
<input class=PC_1 type=Reset value=Reset>
</DIV>
<input type=hidden name=FormularTitel value=Kontaktformular>
</form>
<p class="captcha"><img src="captcha/captcha.php" border="0" title="Sicherheitscode"> <input type="text" name="sicherheitscode" size="5"><br>Bitte geben Sie hier den Code ein. Danke.</p>
</body>
</html>
Das 2. Dokumen ist: "captchapruef.htm". Hier der Inhalt:
<html>
<head>
<title>Prüfdokument</title>
</head>
<body bgcolor="#DDDDFF">
<?php
session_start();
if(isset($_SESSION['captcha_spam']) AND $_POST["sicherheitscode"] == $_SESSION['captcha_spam']){
unset($_SESSION['captcha_spam']);
}else{
die ("Der Sicherheitscode ist falsch!");
}
$message="";
foreach($_POST as $key => $value)
{
if (is_array($_POST[$key]))
{
$merk=$key;
$liste="";
foreach($_POST[$key] as $key => $value)
{
$liste="$liste\n$value";
}
$message="$message\n\n$merk\n$liste";
} else
{
if ($key == "ToMail") {$email=$value;}
if ($key == "FormularTitel") {
$titel=str_replace("#", " ", $value);
}
$message="$message\n\n$key\n$value";
}
}
mail($email,$titel,$message,"From: <$email>");
?>
Vielen Dank für Ihre Nachricht, wir werden uns umgehend bei Ihnen melden.
</body>
</html>
Dann habe ich einen Ordner mit dem Namen "captcha" angelegt.
Hier sind drinnen: "capcha.php", "fehler.php" und das BG-Bild "captcha1.PNG".
Das script captcha.php ist so:
<?php
session_start();
unset($_SESSION['captcha_spam']);
function randomString($len) {
srand(date("s"));
//Der String $possible enthält alle Zeichen, die verwendet werden sollen
$possible="ABCDEFGHJKLMNPRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789";
$str="";
while(strlen($str)<$len) {
$str.=substr($possible,(rand()%(strlen($possible))),1);
}
return($str);
}
$text = randomString(5); //Die Zahl bestimmt die Anzahl stellen
$_SESSION['captcha_spam'] = $text;
header('Content-type: image/png');
$img = ImageCreateFromPNG('captcha1.PNG'); //Backgroundimage
$color = ImageColorAllocate($img, 0, 0, 0); //Farbe
$ttf = $_SERVER['DOCUMENT_ROOT']."/captcha/XFILES.TTF"; //Schriftart
$ttfsize = 25; //Schriftgrösse
$angle = rand(0,5);
$t_x = rand(5,30);
$t_y = 35;
imagettftext($img, $ttfsize, $angle, $t_x, $t_y, $color, $ttf, $text);
imagepng($img);
imagedestroy($img);
?>
... und "fehler.php" ist so aufgebaut:
<?php
session_start();
echo "<h2>Infos über das Captcha</h2>";
unset($_SESSION['captcha_spam']);
$text = rand(1000,10000); //Zufallszahl
function encrypt($string, $key) {
$result = '';
for($i=0; $i<strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return base64_encode($result);
}
$_SESSION['captcha_spam'] = encrypt($text, "8h384ls94"); //Key
$_SESSION['captcha_spam'] = str_replace("=", "", $_SESSION['captcha_spam']);
echo "Zahlencode: ".$text."<br>";
echo "Session Captcha: ".$_SESSION['captcha_spam']."<br>";
$img = ImageCreateFromPNG('captcha.PNG'); //Backgroundimage
$color = ImageColorAllocate($img, 0, 0, 0); //Farbe
$ttf = $_SERVER['Document_Root']."/arial.ttf"; //Schriftart
echo "Schriftpfad: ".$ttf."<br>";
$ttfsize = 25; //Schriftgrösse
$angle = rand(0,5);
$t_x = rand(5,50);
$t_y = 35;
imagettftext($img, $ttfsize, $angle, $t_x, $t_y, $color, $ttf, $text);
error_reporting(E_ALL);
echo "Image (Zeichenwirrwar):<br>";
imagepng($img);
imagedestroy($img);
?>
Tja, aber es funktioniert leider nicht.
Für Deine angebotene Hilfe bin ich Dir jedoch sehr dankbar. Danke.
Gruß
Jago