PHP img capture

Alles, was PHP betrifft, kann hier besprochen werden.

PHP img capture

Postby mconster » 05. August 2008 23:15

hallo und guten tag!
ich habe vor ein loginscript zuschreiben, das mehrere loginversuche erkennen kann und nach 3 oder meherern versuchen dann ein img-capture (ich bin mir nicht sicher ob man das wirklich so nennt. also ich meine eine imgdatei die buchstaben und zahlen enthält - also gegen bots) erstellt, ausgibt und dann eben eine abfrage dazu stattfindet. die überprüfung und das loginscript ist weniger das problem.
ich habe da ein script gefunden, dass schon mal ein bild erstellen kann.
http://www.lovetalk.de/computer-ecke/40 ... ieren.html
ich nenne es mal img.php:
Code: Select all
 
<?php
header ("Content-type: image/jpg");

$key0 = "G";
$key1 = "7";
$key2 = "1";
$key3 = "6";
$key4 = "3";
$key5 = "1";
$key6 = "p";

$key = "$key0 $key1 $key2 $key3 $key4 $key5 $key6";

$bild = ImageCreate (150, 50);

$weiss = ImageColorAllocate ($bild, 255, 255, 255);
$schwarz = ImageColorAllocate ($bild, 0, 0, 0);

$gruen = ImageColorAllocate ($bild, 67,168,47);
$rot = ImageColorAllocate ($bild, 255,0,0);

$blau = ImageColorAllocate ($bild, 90, 138, 201);
$hellblau = ImageColorAllocate ($bild,170,200,242);

imageFilledRectangle($bild,20,20,280,130,$weiss);

/* Linien */
imageline($bild,0,10,150,10,$schwarz);
imageline($bild,0,20,150,20,$schwarz);
imageline($bild,0,30,150,30,$schwarz);
imageline($bild,0,40,150,40,$schwarz);
imageline($bild,0,50,150,50,$schwarz);

imageline($bild,20,50,10,0,$gruen);
imageline($bild,40,50,10,0,$gruen);
imageline($bild,60,50,10,0,$gruen);
imageline($bild,80,50,10,0,$gruen);
imageline($bild,100,50,10,0,$gruen);
imageline($bild,120,50,10,0,$gruen);
imageline($bild,140,50,10,0,$gruen);

imageline($bild,0,50,80,20,$gruen);
imageline($bild,0,50,80,40,$gruen);
imageline($bild,0,50,80,60,$gruen);
imageline($bild,0,50,80,80,$gruen);
imageline($bild,0,50,80,100,$gruen);
imageline($bild,0,50,80,120,$gruen);
imageline($bild,0,50,80,140,$gruen);


/* Diagonale */
imageline($bild,150,50,0,0,$schwarz);
imageline($bild,0,50,150,0,$schwarz);

/* Rahmen */
imageline($bild,0,0,150,0,$schwarz);
imageline($bild,0,49,150,49,$schwarz);
imageline($bild,0,50,0,0,$schwarz);
imageline($bild,149,50,149,0,$schwarz);

/* A B C D | A: oben, B: linie von oben bis unten, C: unten, D: ab wann oben..(breite) */

$polygon_werte = array(20,130,50,110,70,90,90,50,110,100,120,150);

imagepolygon($bild,$polygon_werte,6,$hellblau);
ImageString ($bild, 10, 25, 18, $key, $schwarz);
ImagePNG ($bild);
?>

das script alleine funktioniert ja.
nur ich krieg das nicht mit den include in mein login.php hin:
Code: Select all
....
include('img.php');
....

also include steht zwischen html und php codes-mittendrin
die fehler meldung lautet:
Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at /Applications/xampp/xamppfiles/htdocs/admin_CS_login.php:10) in /Applications/xampp/xamppfiles/htdocs/piccap.php on line 1
�PNG  ��� IHDR�������2���L�?)���PLTE������C�/���Z�ɪ��F��o���IDATH��� �� �!' ����!7_�O۾��Ȗq#҄�� ��ZK��2�ThK�VC���q�5�IƢ�O0T����o���J��_�TjbA�o�"�i�~�֥�� 5R��,H KK��}_��%aһ��%m��1�6�`˛��L]Y��|��E*��q�itS}(5���Mu���ZX�ƹot �`[���F*���6�� k�F��^j�2��2ַRi�=��w������������ў��ԙI�ܥQ�0��X4�\,Jn@cj�GQ��}�b��h��(KM�}�����|b�!�\��RX0^?��L��� �52 R�R(�+nY��ڿǕA,� �#Ջ�J,,�pS�E�U�"�9_�Cz�ȖJU��#��QK"�=J1��bM���u-���z�սfܶdw�-�kiyy���?���� ��y���H���š��{����vkws�‚��m��Q�� RQ� �)w����<���a;��6 ���Na��]�v�tܙ��

ok nachdem ich gegoogelt hab was Warning: Cannot modify header information - headers already sent by überhaupt für eine fehler meldung ist hab ich festgestellt das die headers immer am anfang eines script stehen müssen, sonst bekomm ich eben diesen fehler.
also habe ich den header einfach in mein login.php ganz am anfach ohne lehrzeichen geschrieben. und den restlichen code aus img.php dann einfach später im include dazugehängt.

in login.php:
Code: Select all
<?php header ("Content-type: image/jpg");?>
... html, php....html.....balbalab
include('img.php');

in img.php nun ohne <?php header ("Content-type: image/jpg");?>
Code: Select all
<?php

$key0 = "G";
$key1 = "7";
$key2 = "1";
$key3 = "6";
$key4 = "3";
$key5 = "1";
$key6 = "p";

$key = "$key0 $key1 $key2 $key3 $key4 $key5 $key6";

$bild = ImageCreate (150, 50);

$weiss = ImageColorAllocate ($bild, 255, 255, 255);
$schwarz = ImageColorAllocate ($bild, 0, 0, 0);

$gruen = ImageColorAllocate ($bild, 67,168,47);
$rot = ImageColorAllocate ($bild, 255,0,0);

$blau = ImageColorAllocate ($bild, 90, 138, 201);
$hellblau = ImageColorAllocate ($bild,170,200,242);

imageFilledRectangle($bild,20,20,280,130,$weiss);

/* Linien */
imageline($bild,0,10,150,10,$schwarz);
imageline($bild,0,20,150,20,$schwarz);
imageline($bild,0,30,150,30,$schwarz);
imageline($bild,0,40,150,40,$schwarz);
imageline($bild,0,50,150,50,$schwarz);

imageline($bild,20,50,10,0,$gruen);
imageline($bild,40,50,10,0,$gruen);
imageline($bild,60,50,10,0,$gruen);
imageline($bild,80,50,10,0,$gruen);
imageline($bild,100,50,10,0,$gruen);
imageline($bild,120,50,10,0,$gruen);
imageline($bild,140,50,10,0,$gruen);

imageline($bild,0,50,80,20,$gruen);
imageline($bild,0,50,80,40,$gruen);
imageline($bild,0,50,80,60,$gruen);
imageline($bild,0,50,80,80,$gruen);
imageline($bild,0,50,80,100,$gruen);
imageline($bild,0,50,80,120,$gruen);
imageline($bild,0,50,80,140,$gruen);


/* Diagonale */
imageline($bild,150,50,0,0,$schwarz);
imageline($bild,0,50,150,0,$schwarz);

/* Rahmen */
imageline($bild,0,0,150,0,$schwarz);
imageline($bild,0,49,150,49,$schwarz);
imageline($bild,0,50,0,0,$schwarz);
imageline($bild,149,50,149,0,$schwarz);

/* A B C D | A: oben, B: linie von oben bis unten, C: unten, D: ab wann oben..(breite) */

$polygon_werte = array(20,130,50,110,70,90,90,50,110,100,120,150);

imagepolygon($bild,$polygon_werte,6,$hellblau);
ImageString ($bild, 10, 25, 18, $key, $schwarz);
ImagePNG ($bild);
?>

in dem fall bekomm ich dann folgende meldung vom browser:
Code: Select all
http://127.0.0.1/login.php


so... ich hoffe dass ich mich bis jetzt verständlich ausgedrückt habe. ist ja schon sehr spät ;-)

also kann mir irgendwer sagen wie ich eine "img-capture"-abfrage (falls man das so nennt) schreiben kann? hat irgendjemand sinnvolle links mit geeigneten tutorials oder hilfeseiten zu php wo ich ein bisschen über imageerzeugen mit php mit berücksichtigung einer einbindung in ein anderes php script nachlesen kann?
schönen abend und vielen dank[/code]
mconster
 
Posts: 13
Joined: 05. August 2008 22:51

Postby Wiedmann » 06. August 2008 00:52

Code: Select all
include('img.php');

Die Datei "img.php" (mit header) darf in deinem Hauptscript nicht über einen include() eingebunden werden.

Sondern da wo das Bild im HTML Code stehen soll (dein Hauptscript), muss der Browser diese Datei aufrufen:
Code: Select all
<img src="img.php" alt="Captcha">
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby mconster » 06. August 2008 22:15

danke danke! genau das war der fehler, hab einfach nicht gewusst wie das einzubinden gehört. ich hab übringes zwei tutorials seiten zum thema captcha gefunden. wer interesse hat der klickts einfach ;-)
http://www.white-hat-web-design.co.uk/a ... aptcha.php

http://www.stoppt-den-spam.info/webmast ... cript.html
mconster
 
Posts: 13
Joined: 05. August 2008 22:51


Return to PHP

Who is online

Users browsing this forum: No registered users and 9 guests