- Home
- Categorie
- Coding e Sistemistica
- PHP
- script per generazioni immagini probblemi di funzionamento
-
script per generazioni immagini probblemi di funzionamento
Ciao
ho trovato questo script di esempio per generare immagini attraverso del codice php.Pultroppo non sono molto brava con il codice......... e ho riscontrato qualche difficoltà.
Il testo originale era questo:
<?php /* form.php Click Captcha Ver.1 Created on: 4/17/2007 by Ron Hickey http://6tx.net/sc */ //buffer ob_start('ob_gzhandler'); session_start(); // if submit if (($_POST[x])&&(substr($_SESSION[igif], 17) === $_SESSION['afloat'])){ // posted $x = $_POST[x]; // you can remove 4 lines below they are for demo $fname = strip_tags($_POST[fname]); $lname = strip_tags($_POST[lname]); $fname = stripslashes(substr($fname, 0, 12)); $lname = stripslashes(substr($lname, 0, 12)); // you can remove 4 lines above they are for demo // decode, strip string and round numbers $a = base64_decode($_SESSION['afloat']); $b = 0 + $a; $a = explode(" ", $a); $a = $a[3]; $bb = round($b); $aa = round($a); // x coords $gc = explode(" ", '0 19 40 60 82 104 79 100 121 142 163 185'); // check if correct number has been clicked $ac = $aa + 6; if ($bb <= $aa){ $ac = $bb + 1; } //demo wrong number clicked error message below $mess = "ERROR: Sorry " . stripslashes($fname . "_" . $lname) . " wrong number clicked"; // if correct number clicked success if (($x >= $gc[$ac-1]) && ($x <= $gc[$ac])){ // submit your form //demo SUCCESS message below $mess = "SUCCESS: Yes " . stripslashes($fname . "_" . $lname) . " correct number clicked"; } //demo alert message below ?> <script> alert("<?=$mess;?>"); window.location = window.location; </script> <? session_unset(); session_destroy(); ob_end_flush(); exit; } // afloat = base64_encoded random string $afloat = base64_encode(" " . $num1 = rand(0,3) . "." . $num2 = rand(100,999) . " Float " . $num3 = rand(1,4) . "." . $num4 = rand(100,999) . " "); // rectangle x coord $aler = "> 78"; if(round($num1 . "." . $num2) <= round($num3 . "." . $num4)) {$aler = "< 105";} // create random image $_SESSION[igif] = "create_gif.php?a=" . $afloat . ""; $_SESSION['afloat'] = $afloat; ?> <html> <head> <style type="text/css"> /* click image */ .cd { width: 185px; height: 15px; background-image: url(<?=$_SESSION[igif];?>); background-repeat: no-repeat; position: relative; left:<?=rand(-100,100);?>px; bottom:<?=rand(55,80);?>px; z-index: 2; } </style> <script language="JavaScript"> // submit form func function submitform() { // You can remove 6 lines below they are for demo if (document.xcoords.fname.value == "") { alert("Please Enter First Name."); return false;} if (document.xcoords.lname.value == "") { alert("Please Enter Last Name."); return false; } // You can remove 6 lines above they are for demo // if box coord submit else rectangle coord alert // Do not edit javascript below this line. you can edit the alert message if (document.xcoords.x.value <?=$aler;?>) { document.xcoords.submit(); } else { alert("Click number in square identicale to number in rectangle to submit."); } } // image x value function xcoord(event) { image = event.offsetX?(event.offsetX):event.pageX-document.getElementById("coord").offsetLeft; document.xcoords.x.value = image; } </script> </head> <body bgcolor="#FFFFFF"> <div align=center> <table border="0" cellspacing="5" cellpadding="5"> <tr> <td align="center" style="font: 12px Arial; font-weight: normal; color: black; border-color: maroon; border-style: solid; border-width: 1px; background: #FFFFFF; height: 20px; width: 185px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; position: relative; font-weight: normal;">Click Captcha Demo <br> </td> </tr> </table> <table border="0"> <tr> <td> <form name="xcoords" action="<?=$_SERVER['PHP_SELF']; ?>" method="post"> <table border="0" bgcolor="#FFFFFF" cellpadding="5" cellspacing="5" width="400" style="border: 1px solid maroon"> <tr> <td align="right"> <table border="0" cellpadding="5" cellspacing="5" width="300" bgcolor="#FFFFFF"> <tr> <td align="right" valign="middle" style="width: 70px; font: 12px Arial, Helvetica, sans-serif; color: #000000; background:; border-left-width: 1px; border-left-style: solid; border-left-color: maroon; border-bottom-style: solid; border-bottom-color: maroon; border-bottom-width: 1px; padding-top: 2px; padding-right: 5px; padding-bottom: 1px; padding-left: 2px;">First Name:</td> <td align="left" valign="top"><input type="text" name="fname" value="First" style="font: 12px Arial, Helvetica, sans-serif; color: maroon; border-color: maroon; border-style: solid; border-width: 1px; background: #FFFF99; height: 20px; width: 60px; position: relative; font-weight: normal; letter-spacing: 1px; text-align: left; padding-left: 3px;"></td> </tr> <tr> <td align="right" valign="middle" style="width: 70px; font: 12px Arial, Helvetica, sans-serif; color:; background:; border-left-width: 1px; border-left-style: solid; border-left-color: maroon; border-bottom-style: solid; border-bottom-color: maroon; border-bottom-width: 1px; padding-top: 2px; padding-right: 5px; padding-bottom: 1px; padding-left: 2px;">Last Name:</td> <td align="left" valign="top"><input type="text" name="lname" value="Last" style="font: 12px Arial, Helvetica, sans-serif; color: maroon; border-color: maroon; border-style: solid; border-width: 1px; background:; height: 20px; width: 60px; position: relative; font-weight: normal; letter-spacing: 1px; text-align: left; padding-left: 3px;"></td> </tr> </table> </td> </tr><!-- include hidden form input: x >>>>>--><input type="hidden" name="x" /><tr> <td align="center"><table border="0"><tr><td style="font: 11px Arial; color: maroon; border-color: maroon; border-style: solid; border-width: 1px; background: #F8F8FF; height: 30px; width: 189px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; position: relative; font-weight: normal;">Submit: click number in image square identicale to number in image rectangle</td> </tr> <tr><td><p></td></tr> </table></td> </tr></table></form></td><tr> <!-- This line >>>> <div id="coord" onclick="submitform(xcoord(event))" class="cd"></div> >>> Must be outside of form tags <form></form> to work in FF, NS and Opera >>>> --> <td width="390" align="center" valign="top"> <p><div id="coord" onclick="submitform(xcoord(event))" class="cd"></div></td> </tr></table></div> <? ob_end_flush(); ?> ``` e la pagina per generare immagini che porta questo codice:
<?php
/* create_gif.php
Click Captcha Ver.1
Created on: 4/17/2007 by Ron Hickey
http://6tx.net/sc */
//buffer
ob_start('ob_gzhandler');
session_start();
//DEC 67
//get a and decode
//
$a = $_GET['a'];
if ($a == $_SESSION['afloat']){
$a = base64_decode($a);
$im = imagecreatetruecolor (185, 15);
//DEC 79
//random numbers
//
$myn = array($ooon = rand(81,99), $tooo = rand(61,$ooon-1), $trif = rand(41,$tooo-1),
$foey = rand(21,$trif-1), $flit = rand(11,$foey-1));
$rn = array_rand($myn, 5);
$mynum = " " . $myn[$rn[0]] . " " . $myn[$rn[1]] . " " . $myn[$rn[2]] . " " . $myn[$rn[3]] . " " . $myn[$rn[4]] . "";//DEC 68
//get first numbers from string b.bbb"
//
$b = 0 + $a;
//DEC 69
//get last numbers from string "a.aaa
//
$a = explode(" ", $a);
$a = $a[3];
//DEC 66
//round < a.aaa> to nearest number = round a
//
$aa = round($a);
//DEC 89
//round < b.bbb > to nearest number = round b
//
$bb = round($b);
//DEC 82
//string, random click number and line coord
//
$na = 79;
$nb = 185;
$nc = 82;
$nd = 182;
$ims = -1;
$ab = explode(" ", $mynum);
$mystring = "Click $ab[$aa] $mynum";
//DEC 79
//if bb <= aa reverse string and line coord. click number aa = bb + 1
//
if ($bb <= $aa){
$aa = $bb + 1;
$mystring = "" . $mynum . " Click $ab[$aa] ";
$na = 0;
$nb = 106;
$nc = 4;
$nd = 104;
$ims = -9;
}
//DEC 78
//random image color
//
$change = rand(1,9);
$lime = imagecolorallocate($im,0,255,0);
$yellow = imagecolorallocate($im,255,255,0);
$white = imagecolorallocate($im,255,255,255);
$lgray = imagecolorallocate($im,206,206,206);
$gray = imagecolorallocate($im,115,115,115);
$black = imagecolorallocate($im,0,0,0);
$green = imagecolorallocate($im,1,107,0);
$grc = " $lime $yellow $white $lgray $yellow $white $gray $black $green";
$rc = explode(" ", $grc);
$bgc = $rc[$change];
//DEC 72
//line & number colors
//
$bc = imagecolorallocate ($im, 0, 0, 0);
$rd = imagecolorallocate ($im, 255, 0, 0);
$wh = imagecolorallocate ($im, 255, 255, 255);
//DEC 73
//if color = this change line & number color
//
if (($change > 3) && ($change < 7)) { $bc = $rd;}
elseif ($change > 6) { $bc = $wh;}
//DEC 67
//fill image color
//
imagefilledrectangle ($im, 1, 1, 184, 15, $bgc);
imagerectangle ($im, 0, 0, 184, 14, $bc);
//DEC 75
//vertical lines
//
for($i=$na;$i<=$nb;$i+=21)
imageline($im,$i,0,$i,15,$bc);//DEC 69
//image string
//
imagestring ($im, 3, $ims, 1, " $mystring", $bc);
//DEC 89
//header content
//
header("Content-Type: image/gif");
//DEC 48
//send image
//
imagegif($im);
//DEC 55
//destroy image
//
imagedestroy($im);
}
//flush
ob_end_flush();
?>http://www.designgrouparchitetti.it/contattami-1.php Ma come potete vedere voi stessi la pagina non funziona come dovrebbe, non viene carricata nessuna immagine. :x:x:x ho fatto numerosi tentavi ma senza risultato. Poi vorrei che cliccando sul tasto il tutto fosse inviato a questa pagina http://www.designgrouparchitetti.it/contattami2.php ????????? vi chiedo un aiutino per finire queste due pagine. Vi mando anche il link ai due esempi che ho scaricato, magari ho saltato qualcosa per questo non funzionano: http://www.designgrouparchitetti.it/form.php http://www.designgrouparchitetti.it/create_gif.php Grazie a tutti Sabri
-
Allora ho modificato qualcosina.....
l'immagine si vede, viene generata corretamente.adesso però non capisco una cosa.
Quando clicco sopra l'immagine corretta non succede niente..........e poi non rieco a far si che tutti i dati del form una volta confermata l'immagine corretta, vengano inviati ad un'altra pagina.