Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 118,866 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 1,728 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Problems Setting Up CAPTCHA

 
Reply to this topicStart new topic

Problems Setting Up CAPTCHA, Form seems to just ignore it whether its wrong or not.

cbgfilms
post 16 Jul, 2008 - 10:07 AM
Post #1


New D.I.C Head

*
Joined: 14 Jul, 2008
Posts: 22


My Contributions


Hii, I've just tried installing some CAPTCHA right here

But when you press submit on the form, it seems to go through whether the code is wrong, right, or nothing inputted.

Help!

FORM/TABLE CODE:
CODE
<form action="insert.php" method="post">
<table width="393" height="269" border="8" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
  <tr>
    <td width="375" height="253" bgcolor="#0033CC"><table width="397" height="240" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="30"> <div align="center"><span class="style45"><span class="style37">Name</span></span></div></td>
        <td><div align="center" class="style37">:</div></td>
        <td><span class="style45">-</span>
          <input name="name" type="text" id="name" size="35" />
&nbsp;</td>
      </tr>
      <tr>
        <td width="89" height="30"><div align="center"><span class="style37"> Username</span></div></td>
        <td width="10"><div align="center" class="style37">:</div></td>
        <td width="298"><span class="style45">-</span>
            <input name="username" type="text" id="username" size="35" />
          &nbsp;</td>
      </tr>
      <tr>
        <td height="30"><div align="center"><span class="style37">Password</span></div></td>
        <td><div align="center" class="style37">:</div></td>
        <td><span class="style45">-</span>
            <input name="password" type="password" id="password" size="35" />
          &nbsp;</td>
      </tr>
      <tr>
        <td height="30"><div align="center"><span class="style37">Country</span></div></td>
        <td><div align="center" class="style37">:</div></td>
        <td><span class="style45">-</span>
          <input name="country" type="text" id="country" size="35" />
&nbsp;</td>
      </tr>
      <tr>
        <td height="30"><div align="center"><span class="style37">Email</span></div></td>
        <td><div align="center" class="style37">:</div></td>
        <td><span class="style45">-</span>
            <input name="email" type="text" id="email" size="35" />
          &nbsp;</td>
      </tr>
      <tr>
        <td height="30" valign="top"><div align="center">
            <p class="style37">Profile</p>
        </div></td>
        <td valign="top"><div align="center" class="style37"><br />:</div></td>
        <td><span class="style45">-</span>
            <textarea name="profile" cols="27" rows="8" id="profile"></textarea>
          &nbsp;</td>
      </tr>
      <tr>
        <td height="30" valign="top"><div align="center"><span class="style37">CaPtChA</span></div></td>
        <td valign="top"><div align="center"><span class="style37">:</span></div></td>
        <td><p align="left" class="style45">------<img src="<?php echo captchaImgUrl()?>"><br />
              -----
                  <input name="captcha" size="35"/>
            </p>
          </td>
      </tr>
      <tr>
        <td height="30">&nbsp;</td>
        <td>&nbsp;</td>
        <td align="right"><input type="submit" />
          &nbsp;
          <input name="Reset" type="reset" value="Reset" />
          <span class="style45">----</span></td>
      </tr>
    </table></td>
  </tr>
</table>
</form>
User is offlineProfile CardPM

Go to the top of the page


BetaWar
post 16 Jul, 2008 - 11:00 AM
Post #2


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,692



Thanked 64 times

Dream Kudos: 1075
My Contributions


If that is the case it will be a problem on the server side, not the front end, we will need to see the PHP behind the database insert to be able to help.
User is offlineProfile CardPM

Go to the top of the page

cbgfilms
post 16 Jul, 2008 - 11:10 AM
Post #3


New D.I.C Head

*
Joined: 14 Jul, 2008
Posts: 22


My Contributions


QUOTE(BetaWar @ 16 Jul, 2008 - 11:00 AM) *

If that is the case it will be a problem on the server side, not the front end, we will need to see the PHP behind the database insert to be able to help.


CAPTCHA.PHP:
CODE
<?php
        // There had better be NO BLANK LINES OR ANYTHING ELSE
        // before the preceding line!

    // Boutell's Simple PHP Captcha.
    
    // Copyright 2007, Thomas Boutell and Boutell.Com, Inc.
    // Permission granted to use and modify this code as you
    // see fit, provided that you do not represent this code
    // as your own work.

    // Otherwise, feel free to profit from this code
    // in any way you wish.

    // NO CHANGES REQUIRED HERE

        // All settings are in captcha-settings.php, so that you can
    // install an upgraded version of captcha.php without losing them.

        require 'captcha-settings.php';
    // 2007-06-21: if Accountable is present, a session is already started.
    // Calling session_start again will cause problems for Accountable
    if (!$login) {
        session_start();
    }
    if (isset($_GET['captchaimg'])) {
        captchaSendImg();
    } elseif (isset($_GET['captchawav'])) {
        captchaSendWav();        
    } else {
        captchaCode();
    }
    function captchaImgUrl()
    {
        global $captchaimg;
        return $captchaimg;
    }
    function captchaWavUrl()
    {
        global $captchawav;
        return $captchawav;
    }
    function captchaCode()
    {
        global $captchaimg, $captchawav;
        // Don't generate the code twice
        if (!isset($_SESSION['captchacode'])) {
            // Skip f, x and s, they are too hard to tell
            // apart when spoken. Skip l, it is confused
            // routinely with 1.
            $chars = "abcdeghijkmnopqrtuvwyz";
            $code = "";
            $length = mt_rand(5, 7);
            for ($i = 0; ($i < $length); $i++) {
                $char = substr($chars,
                    rand(0, strlen($chars) - 1), 1);
                $code .= $char;
            }
            $_SESSION['captchacode'] = $code;
        }
        $salt = mt_rand(1000000, 2000000);
        if (isset($_SERVER['SCRIPT_URL'])) {
            $scriptUrl = $_SERVER['SCRIPT_URL'];
        } elseif (isset($_SERVER['SCRIPT_URI'])) {
            $scriptUrl = $_SERVER['SCRIPT_URI'];
        } elseif (isset($_SERVER['REQUEST_URI'])) {
            $scriptUrl = $_SERVER['REQUEST_URI'];
        } else {
            die("captcha.php: SCRIPT_URL, SCRIPT_URI and REQUEST_URI are unavailable, I can't find myself");
        }
        $scriptUrl = preg_replace('/\\?.*$/', '', $scriptUrl);
        $captchaimg = $scriptUrl . "?captchaimg=1&captchasalt=$salt";
        $captchawav = $scriptUrl . "?captchawav=1&captchasalt=$salt";
    }
    function captchaDone()
    {
        if ($_SESSION['captchacode']) {
            unset($_SESSION['captchacode']);
        }
        captchaCode();
    }
    function captchaSendImg()
    {
        global $captchaFont;
        # 20071206: If we just called captchaDone, this won't
        # be set up. But there's nothing wrong with wanting
        # a new CAPTCHA in the very same HTTP response.
        if (!isset($_SESSION['captchacode'])) {
            captchaCode();
        }
        $code = $_SESSION['captchacode'];
        $im = imagecreatetruecolor(200, 50);
        imageantialias($im, 1);
        $back = imagecolorallocate($im, 255, 255, 255);
        $fore = imagecolorallocate($im, 0, 0, 0);
        imagefilledrectangle($im, 0, 0, 200, 50, $back);
        $x = mt_rand(10, 20);
        $y = mt_rand(20, 35);
        $length = strlen($code);    
        for ($i = 0; ($i < $length); $i++) {
            $char = substr($code, $i, 1);
            $size = mt_rand(0, 4) + 16.0;
            $angle = mt_rand(0, -45);
            $xoffs = mt_rand(-3, 3);
            $yoffs = mt_rand(-5, 5);
            imagettftext($im, $size, $angle,
                $x + $xoffs, $y + $yoffs,
                $fore, $captchaFont, $char);
            $x += 23;
            $code .= $char;
        }
        // Now add lots of noise to
        // confuse OCR software
        $flakes = (200 * 50) / 16;
        $flakes = mt_rand($flakes * .8, $flakes * 1.2);    
        for ($i = 0; ($i < $flakes); $i++) {
            $x1 = mt_rand(0, 200);
            $y1 = mt_rand(0, 50);
            $x2 = $x1 + mt_rand(-2, 2);
            $y2 = $y1 + mt_rand(-2, 2);
            imageline($im, $x1, $y1, $x2, $y2, $fore);    
        }
        // jpeg is lossy, which is good here, because
        // it makes automated analysis of the captcha
        // a little more difficult.
        header("Content-type: image/jpeg");     
        imagejpeg($im);
        exit(0);
    }
    function captchaSendWav()
    {
        global $captchaSounds;
        # 20071206: If we just called captchaDone, this won't
        # be set up. But there's nothing wrong with wanting
        # a new CAPTCHA in the very same HTTP response.
        if (!isset($_SESSION['captchacode'])) {
            captchaCode();
        }
        $wav = "RIFF";
        # Dummy length for now, we'll patch it
        # when we know the final length
        $riffLengthOffset = strlen($wav);
        $wav .= pack("V", 0);
        $wav .= "WAVE";
        # Now the format chunk
        $wav .= "fmt ";
        # Enough room to describe PCM
        $wav .= pack("V", 16);
        # Select PCM
        $wav .= pack("v", 1);    
        # mono
        $wav .= pack("v", 1);
        # samplerate
        $wav .= pack("V", 22050);
        # byterate
        $wav .= pack("V", 22050);
        # block alignment
        $wav .= pack("v", 1);
        # bits per sample
        $wav .= pack("v", 8);
        # Now the data chunk
        $wav .= "data";
        $code = $_SESSION['captchacode'];
        $sound = "";
        $change = mt_rand(7000, 10000);
        $change /= 10000.0;
        for ($i = 0; ($i < strlen($code)); $i++) {
            $char = substr($code, $i, 1);    
            $char = strtolower($char);
            $lsound = file_get_contents("$captchaSounds/$char.ub");
            $llen = strlen($lsound);
            $nsound = "";
            $prev = 0;
            $smoothFrequency = mt_rand(200, 300);
            for ($j = 0; ($j < $llen); $j++) {
                $byte = ord(substr($lsound, $j, 1));
                # Change volume slightly to thwart attempts
                # to just recognize the same series of bytes
                $byte *= $change;
                # Smooth in an occasional extra byte to thwart
                # attempts to simply calculate letter lengths
                if (mt_rand(0, $smoothFrequency) == 0) {
                    $smooth = ($byte + $prev) / 2.0;
                    $nsound .= pack("C", $smooth);
                }
                $nsound .= pack("C", $byte);
                $prev = $byte;
            }
            $sound .= $nsound;
        }
        $wav .= pack("V", strlen($sound));
        $wav .= $sound;
        substr_replace($wav, pack("V", strlen($wav) - 8),
            $riffLengthOffset, 4);
        $clength = strlen($wav);
        header("Content-length: $clength");
        header("Content-type: audio/wav");     
        echo($wav);
        exit(0);
    }
    function captchaBasePath()
    {
        $src = __FILE__;
        $path = preg_replace('/\/[^\/]+$/', '', $src);
        return $path;
    }
?>
User is offlineProfile CardPM

Go to the top of the page

JBrace1990
post 16 Jul, 2008 - 12:27 PM
Post #4


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 461



Thanked 20 times

Dream Kudos: 350
My Contributions


that's not really helpful either....

but I think I know what you're doing wrong, because i've done it before... when you're using a captcha and set a session with the captcha values, it's not right until the next page, so on the next page you need to check if the session equals what the captcha said.... if it does equal it, then you insert it, otherwise you display that it's wrong =)
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/13/08 01:58AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month