


| Besucher |
| Heute |
474 |
| gestern |
1.156 |
| Gesamt |
7.334.190 |
| Galerie |
|
|
|
powie.de /
Forum /
PHP /
PHP - Allgemein /
Captcha Klasse
|
|
Anzahl Beiträge: 4
, Neue Antworten.
, Anzahl gelesen: 1289
|
|
Anzahl Beiträge: 7661
- Alleswisser
getStringFromObj()
|
Um das im Gästebuch und eventuell auch an anderen Stellen in Zukunft zu benutzen hab ich mal ne Klasse konstruiert um einen Captcha zu realisieren.
Das Bild wird simpel angezeigt mit:
1: 2: 3: 4: 5:
|
<?php
session_start();
$pc = new pCaptcha();
$pc->showCaptcha();
?>
|
Überprüft werden kann es auf dem folgenden Formular simpel mit:
1: 2: 3: 4: 5:
|
<?php
if ( $_SESSION['pcaptchacode'] == $_POST['code'] ) {
//rischtisch
}
?>
|
Wenn jemand Ideen dazu hat..... Bitte her damit.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88:
|
<?php
class pCaptcha
{
var $pcap_fontsize; //Schriftgrösse
var $pcap_font; //Schriftart (ttf)
var $pcap_code; //Der CODE
var $pcap_len; //Codelänge
var $pcap_bg; //Hintergrund
// PHP 5 Constructor
function __construct( $pcap_code = "" )
{
$this->pcap_code = "";
$this->pcap_font = "captcha.ttf";
$this->pcap_bg = "captcha.png";
$this->pcap_fontsize = 24;
$this->pcap_len = 6;
if ($this->pcap_code == "" ) {
$this->newCode();
} else {
$_SESSION['pcaptchacode'] = $this->pcap_code;
}
}
// PHP 4 Contructor
function pCaptcha( $pcap_code = "" )
{
$this->__construct( $pcap_code ) ;
}
function showCaptcha ()
{
$img_format = 'png';
//Daten des BG
$imgsize = GetImageSize($this->pcap_bg);
switch($imgsize[2]):
case 1 : $bg = ImageCreateFromGIF($this->pcap_bg);
break;
case 2 : $bg = ImageCreateFromJPEG($this->pcap_bg);
break;
case 3 : $bg = ImageCreateFromPNG($this->pcap_bg);
break;
endswitch;
//Textgrösse
$pos = imagettfbbox($this->pcap_fontsize,0,$this->pcap_font,$this->pcap_code);
//var_dump($pos);
$width = intval(abs($pos[0])+abs($pos[2])+6);
$height = intval(abs($pos[1]+$pos[7])+6);
$posx = 3;
$posy = $height - 3;
$pcap_im = imagecreatetruecolor($width,$height);
imagecopyresampled($pcap_im,$bg,0,0,0,0,$width,$height,ImageSX($bg),ImageSY($bg));
//Text einfügen
// colors
$color_white = imagecolorallocate($pcap_im, 0xFF, 0xFF, 0xFF);
$color_black = imagecolorallocate($pcap_im, 0x00, 0x00, 0x00);
imagettftext($pcap_im,$this->pcap_fontsize,0,$posx,$posy,$color_black,$this->pcap_font,$this->pcap_code);
imageinterlace($pcap_im,false);
$pcap_image = 'image'.$img_format;
// sending image
header('Content-type: image/'.$img_format);
$pcap_image($pcap_im);
}
function newCode ()
{
if ( !isset($_SESSION['pcaptchacode']) ) {
$iid= md5(uniqid(rand()));
$iid= substr($iid,0,$this->pcap_len);
$_SESSION['pcaptchacode'] = $iid;
$this->pcap_code = $iid;
} else {
$this->pcap_code = $_SESSION['pcaptchacode'];
}
}
function delCode()
{
if ( isset($_SESSION['pcaptchacode']) ) {
unset ( $_SESSION['pcaptchacode'] );
}
}
}
?>
|
*Never say Never* - Dropbox ZumoDrive
|
Anzahl Beiträge: 80
- Supermember
|
ich weiss, es ist PEAR, aber um schönere Passwörter zu generieren wäre es doch ganz nett:
anstatt:
1: 2:
|
$iid= md5(uniqid(rand()));
$iid= substr($iid,0,$this->pcap_len);
|
müsste dann
1: 2:
|
require_once "Text/Password.php";
$iid = Text_Password::create($this->pcap_len, 'pronounceable');
|
da rein.
pronounceable heisst: für einen englischsprachigen Menschen aussprechbar.
es gibt noch
unpronounceable
passwords based on a given string
Gruß,
D-Day
Couro do Brasil
|
Anzahl Beiträge: 33
- Member
|
Hallo Powie,
Nette Features wären z.B. noch:
- Zufällige Schriftfarbe für jedes Zeichen
- Zufällige Schriftart für jedes Zeichen
- Zufällige Schriftgröße für jedes Zeichen
- Zufällige Schriftwinkel für jedes Zeichen (0 bis +/- 30 Grad)
- Unterschiedlicher Abstand der Zeichen voneinander sowohl in der Höhe als auch in der Breite
- Variabel generierter Hintergrund
- Verzerrte Zeichen
Also in etwas die Funktionen die die HN CAPTCHA Class bietet.
Gruß Smith
|
Anzahl Beiträge: 7661
- Alleswisser
getStringFromObj()
|
das ist immer eine Frage der notwendigkeit, ich glaube um den "Zweck" zu erfüllen reicht die aktelle Version absolut vollkommen aus.
Ich persönlich ärgere mich oft über Captcha Grafiken bei denen man raten muss um bestimmte Zeichen zu erkennen.
*Never say Never* - Dropbox ZumoDrive
|
|
|
Aktuelle Tags
|
|
php
Android
Cyanogen
root
Dream
HTC
Modellflug
WDSL
mySQL
PHPEdit
PowieSys
G1
Breitband
UTF-8
Windows
Maverick
Market
Avatar
IDE
Restore
|

|