Collapz
16.12.2011, 01:37
Ich hab mal ein kleines Formular mit captcha abfrage programmiert.
Die captcha wird errechnet aus der ip adresse und wie multipliziert mit einer random zahl.
Ist ganz praktisch wenn man keine lust hat mit datenbanken etc zu arbeiten.
Ihr solltet ne font ".ttf" im ordner haben und die zeile var $font = 'monofont.ttf'; dann entsprechend ersetzen.
Funktioniert nicht auf jedem Webspace da irgendwelche gdi bzw sachen aktiviert sein müssen viel spaß!
sehe grad dass der code hier im forum buggy angezeigt wird hier richtig :
http://pastebin.com/iceXxdm7
<?php
$multiplikator = rand(100, 1000);
function styler() {
?><style> body {color:white;text-shadow:0 1px 0 rgba(0, 0, 0, 0.5);font-family:arial;font-size:12px !important;}
input {background:none repeat scroll 0 0 rgba(0, 0, 0, 0.25);border:0;color:white;text-shadow:0 1px 0 rgba(0, 0, 0, 0.5);}
td {color:white;font-size:11px}
.two {box-shadow: 0 0 4px 0 rgba(255, 255, 255, 0.4);border:0;background:none repeat scroll 0 0 rgba(0, 0, 0, 0.25);color:rgba(255,255,255,0.88);font-family:arial;text-shadow:0 1px 0 rgba(0, 0, 0, 0.5);}
img {background:rgba(0,0,0,0.7);position:relative;top: 4px;left:2px;}
</style><?php
}
if(isset($_GET["img"])) {} else { if(isset($_GET["write"])) {} else { styler();
?><form name="input" action="?write=1&code=<?php echo $multiplikator; ?>" method="post">
<table><tr><td>
Titel :</td><td> <input style="width:570px;" type="text" name="title"></td></tr><tr><td>
<br>Beschreibung : </td><td><TEXTAREA type="text" class="two" style="height:200px;width:570px;" name="desc"></TEXTAREA></td></tr><tr><td>
<br>Embedcode/Filehoster : </td><td><TEXTAREA class="two" type="text" style="height:200px;width:570px;" name="hoster"></TEXTAREA></td></tr><tr><td>
<br>Bild url : </td><td><input style="width:570px;" type="text" name="image"></td></tr><tr><td>
<br>captcha Code: </td><td><input type="text" name="captcha"><?php echo "<img src=?img=$multiplikator>"; ?></td></tr><tr><td>
<br>Optional Uploader Name: </td><td><input type="text" name="namer"></td></tr><tr><td>
<br><input type="submit" value="Eintragen" /></td></tr>
</tr></table></form>
<?php
}}
if(isset($_GET["write"]) and isset($_GET["code"])) {
styler();
if(strlen($_POST["image"]) > 0 and strlen($_POST["captcha"]) > 0 and strlen($_POST["hoster"]) > 0 and strlen($_POST["desc"]) > 0 and strlen($_POST["title"]) > 0) {
$captcha_input = $_POST["captcha"];
if (is_numeric($captcha_input)) { //CHECK CAPTCHA
$code = "1"; $multiplikator =$_GET["code"];
$code .= $multiplikator * substr(ereg_replace("\.", "", $_SERVER['REMOTE_ADDR']),1,2);
if ($code == $captcha_input) { //CAPTCHA RICHTIG -->eintragen
$timestamp = time();$datum = date("d_m_Y",$timestamp);$uhrzeit = date("H_i_s",$timestamp);
$datei = fopen("$datum.$uhrzeit.txt","a+");
rewind($datei);
fwrite($datei, $_POST["title"]."\n\n\n------------".$_POST["desc"]."\n\n------------".$_POST["hoster"]."\n\n------------".$_POST["image"]."\n\n------------".$_POST["namer"]);
fclose($datei);
echo "Danke für deinen Eintrag! Er wird in kürze überprüft..";
} else {echo "falsche Captcha eingabe!";}
} else {echo "falsche Captcha eingabe!";}
}
else {
echo "Unvollständig!";
}
}
?><?php
if(isset($_GET["img"])) {
class CaptchaSecurityImages {
var $font = 'monofont.ttf';
function CaptchaSecurityImages($width='120',$height='30',$c haracters='6') {$zufallszahl = rand(1000, 100000);
$code = "1"; $multiplikator =$_GET["img"];
$code .= $multiplikator * substr(ereg_replace("\.", "", $_SERVER['REMOTE_ADDR']),1,2);//$this->generateCode($characters);
$imgA = imagecreate(90, 18);
// $colorA['lime'] = imagecolorallocate($imgA, 0x00, 0xFF, 0x00);
$colorA['red'] = imagecolorallocate($imgA, 0x00, 0x00, 0x00);
$colorA =ImageColorAllocate($imgA, 75, 75, 75);
$ttfA = "monofont.ttf";
$ttfsizeA = 20;
$angleA =rand(0,5);
$t_xA = 0;rand(5,30);
$t_yA = 20;
imagettftext($imgA, $ttfsizeA, $angleA, $t_xA, $t_yA, $colorA, $ttfA, $code);
imagecolortransparent($imgA, $colorA['red']);
header("Content-type: image/png");
imagepng($imgA);
// imagedestory($imgA);
}
}
$captcha = new CaptchaSecurityImages(2 * 20, 32, 3);
}
?>
Die captcha wird errechnet aus der ip adresse und wie multipliziert mit einer random zahl.
Ist ganz praktisch wenn man keine lust hat mit datenbanken etc zu arbeiten.
Ihr solltet ne font ".ttf" im ordner haben und die zeile var $font = 'monofont.ttf'; dann entsprechend ersetzen.
Funktioniert nicht auf jedem Webspace da irgendwelche gdi bzw sachen aktiviert sein müssen viel spaß!
sehe grad dass der code hier im forum buggy angezeigt wird hier richtig :
http://pastebin.com/iceXxdm7
<?php
$multiplikator = rand(100, 1000);
function styler() {
?><style> body {color:white;text-shadow:0 1px 0 rgba(0, 0, 0, 0.5);font-family:arial;font-size:12px !important;}
input {background:none repeat scroll 0 0 rgba(0, 0, 0, 0.25);border:0;color:white;text-shadow:0 1px 0 rgba(0, 0, 0, 0.5);}
td {color:white;font-size:11px}
.two {box-shadow: 0 0 4px 0 rgba(255, 255, 255, 0.4);border:0;background:none repeat scroll 0 0 rgba(0, 0, 0, 0.25);color:rgba(255,255,255,0.88);font-family:arial;text-shadow:0 1px 0 rgba(0, 0, 0, 0.5);}
img {background:rgba(0,0,0,0.7);position:relative;top: 4px;left:2px;}
</style><?php
}
if(isset($_GET["img"])) {} else { if(isset($_GET["write"])) {} else { styler();
?><form name="input" action="?write=1&code=<?php echo $multiplikator; ?>" method="post">
<table><tr><td>
Titel :</td><td> <input style="width:570px;" type="text" name="title"></td></tr><tr><td>
<br>Beschreibung : </td><td><TEXTAREA type="text" class="two" style="height:200px;width:570px;" name="desc"></TEXTAREA></td></tr><tr><td>
<br>Embedcode/Filehoster : </td><td><TEXTAREA class="two" type="text" style="height:200px;width:570px;" name="hoster"></TEXTAREA></td></tr><tr><td>
<br>Bild url : </td><td><input style="width:570px;" type="text" name="image"></td></tr><tr><td>
<br>captcha Code: </td><td><input type="text" name="captcha"><?php echo "<img src=?img=$multiplikator>"; ?></td></tr><tr><td>
<br>Optional Uploader Name: </td><td><input type="text" name="namer"></td></tr><tr><td>
<br><input type="submit" value="Eintragen" /></td></tr>
</tr></table></form>
<?php
}}
if(isset($_GET["write"]) and isset($_GET["code"])) {
styler();
if(strlen($_POST["image"]) > 0 and strlen($_POST["captcha"]) > 0 and strlen($_POST["hoster"]) > 0 and strlen($_POST["desc"]) > 0 and strlen($_POST["title"]) > 0) {
$captcha_input = $_POST["captcha"];
if (is_numeric($captcha_input)) { //CHECK CAPTCHA
$code = "1"; $multiplikator =$_GET["code"];
$code .= $multiplikator * substr(ereg_replace("\.", "", $_SERVER['REMOTE_ADDR']),1,2);
if ($code == $captcha_input) { //CAPTCHA RICHTIG -->eintragen
$timestamp = time();$datum = date("d_m_Y",$timestamp);$uhrzeit = date("H_i_s",$timestamp);
$datei = fopen("$datum.$uhrzeit.txt","a+");
rewind($datei);
fwrite($datei, $_POST["title"]."\n\n\n------------".$_POST["desc"]."\n\n------------".$_POST["hoster"]."\n\n------------".$_POST["image"]."\n\n------------".$_POST["namer"]);
fclose($datei);
echo "Danke für deinen Eintrag! Er wird in kürze überprüft..";
} else {echo "falsche Captcha eingabe!";}
} else {echo "falsche Captcha eingabe!";}
}
else {
echo "Unvollständig!";
}
}
?><?php
if(isset($_GET["img"])) {
class CaptchaSecurityImages {
var $font = 'monofont.ttf';
function CaptchaSecurityImages($width='120',$height='30',$c haracters='6') {$zufallszahl = rand(1000, 100000);
$code = "1"; $multiplikator =$_GET["img"];
$code .= $multiplikator * substr(ereg_replace("\.", "", $_SERVER['REMOTE_ADDR']),1,2);//$this->generateCode($characters);
$imgA = imagecreate(90, 18);
// $colorA['lime'] = imagecolorallocate($imgA, 0x00, 0xFF, 0x00);
$colorA['red'] = imagecolorallocate($imgA, 0x00, 0x00, 0x00);
$colorA =ImageColorAllocate($imgA, 75, 75, 75);
$ttfA = "monofont.ttf";
$ttfsizeA = 20;
$angleA =rand(0,5);
$t_xA = 0;rand(5,30);
$t_yA = 20;
imagettftext($imgA, $ttfsizeA, $angleA, $t_xA, $t_yA, $colorA, $ttfA, $code);
imagecolortransparent($imgA, $colorA['red']);
header("Content-type: image/png");
imagepng($imgA);
// imagedestory($imgA);
}
}
$captcha = new CaptchaSecurityImages(2 * 20, 32, 3);
}
?>