Jump to content

Captcha problem ? Cant solve it


Rommeo

Recommended Posts

hi

i coded a simple captcha script but that does not work properly..

my problem is

 

i have an index html.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
.
.
.// form POST TO securitycheck.php
<img src="securitycode.php" alt="security code">
.// form end
.

and my securitycode.php ;

// no doctype info-just code. 
$md5 = md5(rand(0,999)); // security code
$pass = $md5;
create_image($pass)
$_SESSION['security_code'] = $pass;
header("Content-Type: image/jpeg"); 
// create_image function

and my securitycheck.php

if ( $postedsecuritycode ==  $_SESSION['security_code'] ) 
// this is where the problem is 

i cant receive the  $_SESSION['security_code'] from the file securitycode.php .. that does not work. How can i take that from there ? How do the people solve it ? ll be glad if anyone can help. Working on this part for about a week ..

 

Thanx in advance.

Link to comment
Share on other sites

Here's a working example, maybe it will help you get your script working:

(example: http://xtopolis.com/z_phpfreaks/captcha/index.php)

index.php

<?php
  session_start();
//------------------

if(isset($_POST['captcha'])){
  if($_POST['captcha'] == $_SESSION['security_code']){
    echo '<font color="green">Success!</font>';
    echo '<br />The code was: '.$_SESSION['security_code'];
  }else{
    echo '<font color="red">WRONG</font>';
  }

echo '<br /><a href="index.php">Main</a>';
}else{

?>

<html>
<head>
</head>

<body>
  <form method="post">
  <img src="captcha.php" />
  Captcha: <input type="text" name="captcha" />
  <br /><input type="submit" value="Code In" />
  </form>
</body>
</html>
<?php } ?>

captcha.php

<?php
session_start();

$md5 = md5(rand(0,999)); // security code

$_SESSION['security_code'] = $md5;

$my_img = imagecreate( 310, 60 );
$background = imagecolorallocate( $my_img, 92, 64, 51 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 255 );
imagestring( $my_img, 5, 10, 25, $md5, $text_colour );

header( "Content-type: image/jpeg" );
imagejpeg( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
$md5 = '';

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.