powie.de - php
pic
pic
pic
Besucher
Heute 474
gestern 1.156
Gesamt 7.334.190
Galerie
DSCF0116.JPG
Newsletter
E-Mail Adresse angeben, um sich für den Newsletter anzumelden
powie.de / Forum
forum
Forum
  register
Registrierung
  search
Suchen
  member
Mitglieder
  help
Hilfe
  login
Login
 
powie.de / Forum / PHP / PHP - Allgemein / Captcha Klasse
Anzahl Beiträge: 4 , Neue Antworten. , Anzahl gelesen: 1289
reply print
on Powie
Captcha Klasse - 10.01.2006 21:19:04 top
icq skype
Anzahl Beiträge: 7661 - Alleswisser
getStringFromObj()
avatar
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 
$bg ImageCreateFromGIF($this->pcap_bg);
            break;
        case 
$bg ImageCreateFromJPEG($this->pcap_bg);
            break;
        case 
$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_im0xFF0xFF0xFF);
        
$color_black    imagecolorallocate($pcap_im0x000x000x00);
        
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']) ) {
            
$iidmd5(uniqid(rand()));
            
$iidsubstr($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
off D-Day
Captcha Klasse - 11.01.2006 09:27:46 top

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
off smith
Captcha Klasse - 03.03.2006 15:16:05 top

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
on Powie
Captcha Klasse - 03.03.2006 15:17:55 top
icq skype
Anzahl Beiträge: 7661 - Alleswisser
getStringFromObj()
avatar
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
Board Ändern
Springe zu:
Optionen
[ Alles als gelesen markieren ] [ Neues Thema ] [ Nutzungsregeln ] [ Statistik ]
Neuer Content
blog Smarty, mySQL und UTF-8
forum Zwei dynamische Auswahlboxen
forum PHP / MySQL Tree View
forum Dynamische Dropdown-Listen mit Daten aus MySQL
news pForum 1.31.1
forum PM delete und move vermischt
forum SQL Select: 100
art G1 / HTC Dream - CM6
blog Cyanogen Mod 6 - DSP
blog Android Market Download hängt - meine Lösung
Login
Benutzer:
Passwort:
Speichern:
[ Registrierung | Passwort vergessen ]
Aktuelle Tags
php Android Cyanogen root Dream HTC Modellflug WDSL mySQL PHPEdit PowieSys G1 Breitband UTF-8 Windows Maverick Market Avatar IDE Restore
Umfrage
Benutzt du Internet auf deinem Handy?
nein
ja

be-webspace

© Thomas Ehrhardt - 2005 - www.powie.de - Powie - Kontakt: te at powie dot de - geparsed in 0,0839 sec - 03.09.2010, 11:39 - Stats -
php mysql phpedit pSys smarty smarty
PowieSys - 0.8.0 - © Powie - 2005-2010