[PHP] Captcha ins Gästebuch einbinden

Dieses Thema im Forum "Webentwicklung" wurde erstellt von mySQL, 5. November 2009 .

Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 5. November 2009
    Captcha ins Gästebuch einbinden

    Halli Hallo
    Stehe mal wieder vor einer kleinen Aufgabe. Dachte eigentlich: "Gut, kein Problem, dass ist schnell gemacht". Aber daraus wurde mal wieder nix .

    Möchte das Captcha dieser Seite in ein Gästebuch einbauen:
    Captcha Tutorials mit Erkl

    Eine Datei namen "rechen-captcha.php" ( bei mir rc.php" erzeugt ein Captcha, funktioniert einwandfrei. Die Anzeige im Formular des Bildes sowie das Textfeld funktioniert auch wunderbar.

    Jetzt muss aber noch ein kleines Script mit ins das Gästebuch. Nur hier gibts ein Problem:
    Das Script beginnt mit "session_start();" Deshalb muss es direkt nach ganz oben im Textfenster, es darf nicht eine Leerzeile davor sein, sonst kommen Fehlermeldungen.

    Wie schneidere ich nun also diesen Teil (Captcha):
    PHP:
    <? php 
    session_start
    (); 
    function 
    encrypt ( $string $key ) { 
    $result  ''
    for(
    $i = 0 $i < strlen ( $string );  $i ++) { 
       
    $char  substr ( $string $i 1 ); 
       
    $keychar  substr ( $key , ( $i  strlen ( $key ))- 1 1 ); 
       
    $char  chr ( ord ( $char )+ ord ( $keychar )); 
       
    $result .= $char

    return 
    base64_encode ( $result ); 

    $sicherheits_eingabe  encrypt ( $_POST [ "sicherheitscode" ],  "29jfkd921" ); 
    $sicherheits_eingabe  str_replace ( "=" "" $sicherheits_eingabe ); 
    if(isset(
    $_SESSION [ 'rechen_captcha_spam' ]) AND  $sicherheits_eingabe  ==  $_SESSION [ 'rechen_captcha_spam' ]){ 
    unset(
    $_SESSION [ 'rechen_captcha_spam' ]); 

    // 
    // 
    //Hier kommt das ursprüngliche Script hin. 
    // 
    // 


    ?>
    Richtig in das Gästebuch:

    PHP:
    <html>
    <head>
    <title>---------</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel=stylesheet type="text/css" href="style.css">
    </head>

    <body bgcolor="#FFFFEC" text="#000000" link="#09274B" vlink="#09274B" alink="#155EB5" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#A5B6C1">
      <tr> 
        <td width="67%">
          <div align="left"><img src="grafiken/kopf.jpg" width="695" height="113"></div>
        </td>
        <td width="33%" background="grafiken/kopf-hintergrund.gif"> 
          <div align="right"><img src="grafiken/kopf-rechts.jpg" width="75" height="113"></div>
        </td>
      </tr>
    </table>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr valign="top" align="left"> 
        <td height="506"> 
          <table width="770" border="0" cellspacing="0" cellpadding="0" height="510">
            <tr> 
              <td width="135" height="500" valign="top" background="grafiken/verlauf-links.jpg" style="background-repeat:no-repeat"> 

            <?  include( "menu.inc" );  ?>

              </td>
              <td rowspan="2" height="510" align="left" valign="top">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="7%">&nbsp;</td>
                    <td width="93%">&nbsp;</td>
                  </tr>
                  <tr>
                    <td width="7%">&nbsp;</td>
                    <td width="93%">
                      <p class="head1">Gästebuch</p>
                      <b class="head2">Ihre Meinungen und Kommentare</b>
                      <p>
                </p>
                  
       <?
                
    include( "dbopen.php" );
                
    $sent      $_POST [ "sent" ]; 
                
    $name      $_POST [ "name" ]; 
                
    $email      $_POST [ "email" ]; 
                
    $msg          $_POST [ "msg" ]; 

                if (
    $sent
                {
                    
    $trimname    trim ( $name );
                    
    $trimemail   trim ( $email );
                    
    $msg         eregi_replace ( "\n" , "<br>" , $msg );
                    
    $anz1  substr_count ( $msg "href" );
                    if (
    $anz1  2 ) { $anz1  $anz1  substr_count ( $msg "url]" );}
                    if (
    $anz1  2 ) { $anz1  $anz1  substr_count ( $msg "[url" );}
                    if (
    $anz1  2 ) { $anz1  $anz1  substr_count ( $msg "[URL" );}
                    if (
    $anz1  2 ) { $anz1  $anz1  substr_count ( $msg "http://" );}

                    if (
    $anz1  1 )
                    {
                        echo 
    "<br><b>Ihr G&auml;stebucheintrag wird nicht gespeichert, da zuviele Links enthalten sind." ;
                    }
                    else
                    {
                        
    $sql   "INSERT INTO  $t_guestbook  (name, email, msg, datum, ip)" ;
                        
    $sql  .=  "VALUES " ;
                        
    $sql  .=  "(' $name ', ' $email ', ' $msg ', curdate(), ' $REMOTE_ADDR ')" ;
                        
    $result  mysql_query ( $sql $conn );

                        if (
    $result
                        {
                            echo 
    "" ;
                          }
                        else 
                        {
                              echo 
    "<P>" . mysql_error ( $conn );
                        }
                        
    $mailadresse       =   "xxxxxxxxxxxxx"
                        
    $absender           =   "xxxxxxxxxxxxx"
                        
    $text              =   "Name:  $trimname  \nE-Mail:  $trimemail \nURL:  $trimEurl  \nBemerkung:  $msg  \nEintrag löschen: 
                         \n"
    ;
                        
    $text             .=   "Browser:  $HTTP_USER_AGENT \nIP-Adresse:  $REMOTE_ADDR "
                        
    mail " $mailadresse " "Neuer Gästebucheintrag." ,   " $text " ,   "From:  $absender \n" ); 
                    }
                } 
                else
                {
                    echo 
    "<FORM method=\"post\" action=\"1toall.php\"><TABLE border=0>\n" ;
                    echo 
    "<TR><TH align=left>Name:</TH></TR>\n" ;
                    echo 
    "<TR><TD><INPUT type=\"text\" name=\"name\" size=\"35\" style=\"font-family : Verdana, Arial,Helvetica,sans-serif; font-size : 11pt\">" ;
                    echo 
    "</TD></TR>\n" ;
                    echo 
    "<TR><TH align=left>E-Mail:</TH></TR>\n" ;
                    echo 
    "<TR><TD><INPUT type=\"text\" name=\"email\" size=\"35\" style=\"font-family : Verdana, Arial,Helvetica,sans-serif; font-size : 11pt\">" ;
                    echo 
    "</TD></TR>\n" ;
                    echo 
    "<TR><TH valign=top align=left>Nachricht:</TH></TR>\n" ;
                    echo 
    "<TR><TD>" ;
                    echo 
    "<TEXTAREA cols=\"35\" rows=\"6\" name=\"msg\" style=\"font-family : Verdana, Arial,Helvetica,sans-serif; font-size : 11pt\"></TEXTAREA>" ;
                    echo 
    "</TD></TR>\n" ;
                    echo 
    "<TR><td align=center><br>\n" ;
                    echo 
    "<img src=\"rc.php\">" ;
                    echo 
    "<input type=\"text\" name=\"sicherheitscode\" size=\"5\">" ;
                    echo 
    "<INPUT type=\"hidden\" name=\"sent\" value=\"1\"> \n" ;
                    echo 
    "<INPUT type=\"submit\" value=\"Absenden\">&nbsp;&nbsp;\n" ;
                    echo 
    "<INPUT type=\"reset\">\n" ;
                    echo 
    "</TD></TR></TABLE>\n" ;
                    echo 
    "</FORM>" ;
                }
                
    ?>
                <br>
                <?
                    $menge
    = 0 ;
                    
    $tstamp  mktime ( 0 0 0 date ( "m" ),  date ( "d" ),  date ( "Y" ));

                    
    $query   "select msg_id, name, email, msg, datum, kommentar
                             from 
    $t_guestbook
                             order by datum desc, msg_id desc"
    ;
                      
    $result  mysql_query ( $query $conn );

                    while(
    $row  mysql_fetch_object ( $result )) 
                    {
                        echo 
    "\t\t<table border=\"0\" width=\"100%\" cellspacing=\"1\" cellpadding=\"1\">\n" ;
                        echo 
    "<tr><th align=left bgcolor=\"#A5B6C6\">&nbsp;<a href=\"mailto: $row -> email \"> $row -> name </a></th></tr>" ;
                        echo 
    "<tr><td bgcolor=\"#ffffff\"><b>Nachricht: </b> $row -> msg " ;

                        echo 
    "<br><b>Datum: </b>" ;
                        echo 
    date_mysql2german ( $row -> datum );

                        if(
    $row -> kommentar )
                        {
                            echo 
    "<br><b>Kommentar: </b>" ;
                            echo 
    eregi_replace "\\\n" "<br>" $row -> kommentar  );
                            }

                        echo 
    "<br><br></td></tr>" ;
                        echo 
    "</table><br>" ;
                    }


        
    mysql_free_result ( $result );
        
    ?>


                    </td>
                  </tr>
                  <tr>
                    <td width="7%">&nbsp;</td>
                    <td width="93%">&nbsp;</td>
                  </tr>
                </table>
              </td>
            </tr>
            <tr> 
              <td width="135" height="2" valign="top">&nbsp;</td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    <script src="xxxxxxxxxxxxxx" type="text/javascript">
    </script>
    <script type="text/javascript">
    _uacct = "UA-352362-2";
    urchinTracker();
    </script>
    </body>
    </html>
    Über hilfe würde ich mich freuen, ist ja fast für nen guten Zweck Belohnung gibts auch

    //EDIT:
    Habs doch noch selber hinbekommen
     
  2. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.