Rommeo Posted October 3, 2008 Share Posted October 3, 2008 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. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 3, 2008 Share Posted October 3, 2008 Make sure that you have session_start() at the top of all your pages, the very top. Quote Link to comment Share on other sites More sharing options...
Rommeo Posted October 3, 2008 Author Share Posted October 3, 2008 i tried that lot of times.. could not solve it i even put it at the top of my index page.. but cant receive it Quote Link to comment Share on other sites More sharing options...
xtopolis Posted October 3, 2008 Share Posted October 3, 2008 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 = ''; ?> Quote Link to comment Share on other sites More sharing options...
Rommeo Posted October 3, 2008 Author Share Posted October 3, 2008 xtopolis thank you soo much ! now i ll check my codes again maybe i can use ur codes. Thank you again for your help again (: Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.