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
https://forums.phpfreaks.com/topic/126837-captcha-problem-cant-solve-it/
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 = '';

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.