glennl Posted March 19, 2007 Share Posted March 19, 2007 Hi everyone, I have a guestbook scripts which saves the entries in a text-file. Here is the php-code (gb.php): <? $amount=5; if ($_GET['action'] =='write') { header('location: gb.php?action=read&start=0'); $file=fopen('gastenboek.txt','a'); $message=stripslashes($_GET['message']); $message=str_replace("\r",'',$message); $message=str_replace("\n",'{{',$message); fwrite($file,stripslashes($_GET['name']) .'|||'.$_GET['email'].'|||'.date('d-m-Y').'|||'.$_GET['url'].'|||'.$message."\n"); fclose($file); } $start=(isset($_GET['start'])?$_GET['start']:0); $gastenboek=Array(); $gastenboek=file('gastenboek.txt'); ?> <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 19 Jul 1997 05:00:00 GMT"); // Date in the past ?> <SCRIPT language="JavaScript"> var form_submitted = false; function validate(form) { if (form.name.value=="") { alert("You forgot your name!"); return false; } else if (form.message.value=="") { alert("You forgot your message!"); return false; } else if (form.email.value=="") { alert("You forgot your e-mail!"); return false; } if ( form_submitted ) { alert ( "Your form has already been submitted. Please wait..." ); return false; } else { form_submitted = true; return true; } } </SCRIPT> <head> <script type="text/javascript" src="dom-drag.js"></script> <link href="css/styles.css" rel="stylesheet" type="text/css"> <title>guestbook</title> </head> <body bgcolor="#9E9583"> <script type="text/javascript"> //We wrap all the code in an object so that it doesn't interfere with any other code var scroller = { init: function() { //collect the variables scroller.docH = document.getElementById("content").offsetHeight; scroller.contH = document.getElementById("container").offsetHeight; scroller.scrollAreaH = document.getElementById("scrollArea").offsetHeight; //calculate height of scroller and resize the scroller div //(however, we make sure that it isn't to small for long pages) scroller.scrollH = (scroller.contH * scroller.scrollAreaH) / scroller.docH; //if(scroller.scrollH < 15) scroller.scrollH = 15; document.getElementById("scroller").style.height = Math.round(scroller.scrollH) + "px"; //what is the effective scroll distance once the scoller's height has been taken into account scroller.scrollDist = Math.round(scroller.scrollAreaH-scroller.scrollH); //make the scroller div draggable Drag.init(document.getElementById("scroller"),null,0,0,-1,scroller.scrollDist); //add ondrag function document.getElementById("scroller").onDrag = function (x,y) { var scrollY = parseInt(document.getElementById("scroller").style.top); var docY = 0 - (scrollY * (scroller.docH - scroller.contH) / scroller.scrollDist); document.getElementById("content").style.top = docY + "px"; } } } onload = scroller.init; </script> <div id="scrollArea"><div id="scroller"></div></div> <div id="container"> <div id="content"> <span class="redtitle">GUESTBOOK</span> <P> <TABLE width="258" cellspacing="0" cellpadding="0" > </TABLE> <TABLE width="258" cellspacing="0" cellpadding="0"> <TR> <TD class="side"><i> Berichten <? echo $start+1; ?> tot <? echo min($start+$amount,sizeof($gastenboek)); ?>. Totaal van <? echo sizeof($gastenboek); ?> berichten. </i> <HR> <TABLE width="258" cellspacing="0" cellpadding="1"> <? $gastenboek=array_reverse($gastenboek); for ($i=$start;$i<$start+$amount && $i<sizeof($gastenboek);$i++) { list($name,$email,$date,$url,$message)=explode('|||',$gastenboek[$i]); $message=str_replace('{{',"\n",$message); echo ' <TR><TD bgcolor="#5D5C48"><B>'.($email!=""?'<A href="mailto:'.$email.'">'.$name.'</A>':$name).'</td></TR>'."\n"; echo '<TR><TD bgcolor="#5D5C48" colspan=2>'.str_replace("\n",'<BR>',htmlspecialchars($message)).'<br></TD></TR>'."\n"; echo ($url!=""?'<tr><TD bgcolor="#5D5C48" colspan="2" align="left"><font size=1> Homepage: <A href="'.$url.'" target="_blank">'.$url.'</A></font></TD></TR>':'')."\n"; echo'<tr><td bgcolor="#5D5C48" colspan=2><font size=1>Geplaatst op '.$date.'</font></td></tr>'."\n"; echo '<TR><TD colspan=2></TD></TR>'."\n"; echo '<TR><TD colspan=2></TD></TR>'."\n"; echo '<TR><TD colspan=2></TD></TR>'."\n"; echo '<TR><TD colspan=2></TD></TR>'."\n"; echo '<TR><TD colspan=2></TD></TR>'."\n"; } ?> </TABLE> <CENTER> <? if ($start>0) echo '<A href="gb.php?start='.max(0,$start-$amount).'" class="a"><< vorige pagina </A> -- '; if ($start+$amount<sizeof($gastenboek)) echo ' <A href="gb.php?start='.($start+$amount).'" class="a">volgende pagina >></A>'; ?> </CENTER></TD> </TR> </TABLE> <P> <TABLE width="258" cellspacing="0" cellpadding="0" > <TR> <TD class="side"><span class="redtitle">PLAATS NIEUW BERICHT</span></TD> </TR> </TABLE> <TABLE width="258" cellspacing="0" cellpadding="0" > <TR> <TD class="side"> <FORM action="gb.php" method="GET" onSubmit="return validate(this);"> <INPUT type="hidden" name="action" value="write"> <TABLE class="side"> <TR> <TD>Naam:</TD> <TD><INPUT type="text" name="name" size="30"></TD> </TR> <TR> <TD>E-Mail:</TD> <TD><INPUT type="text" name="email" size="30"> </TD> </TR> <TR> <TD>Homepage:</TD> <TD><INPUT name="url" type="text" size="30"> (optional)</TD> </TR> <TR> <TD>Bericht:</TD> <TD><TEXTAREA name="message" cols="40" rows="5"></TEXTAREA></TD> </TR> </TABLE> <input type="submit" name="submit" value="Plaats in gastenboek..."> </FORM> </TD> </TR> </TABLE> </div> </div> <br> </body> </html> Now, I want to insert a captcha in the form. My captcha image is created with captcha.php and this works. But now, I have to integrate the validation in my guestbook-script and there I have problems. I need an extra field like this: <input class="input" type="text" name="norobot"> <img src="captcha.php"> And now, I have to integrate this code somewhere in my gb.php: <?php session_start(); $redirect= $_POST['referer']; if (md5($_POST['norobot']) == $_SESSION['randomnr2']) { // no fail echo "no robot"; } else { // failed echo "robot!"; } ?> Can someone help me please, I'm still learning PHP... Thanks! Link to comment https://forums.phpfreaks.com/topic/43387-captcha-integration-in-guestbook/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.