PdYpsilon Posted July 15, 2008 Share Posted July 15, 2008 Hello there! (in Advance: Iam sorry, my english is very bad) I want to realize a stupid and easy captchasystem with my own made captchapictures and tried to use it in my guestbook. But, I tried so hard to think of an functional captchasystem... I cannot realize it. It seems to hard for me, because: When the user opens my guestbook, I made it that the captchaalways randomize. But When he typed in the captcha, the next step is, that the script recognize this capture which he uses for the next call of the script, compare it and say "yes alright" or "no wrong". This all is not a problem with sessions BUT if THEN, when he wrote it wrong there should be come a new capture. There is my problem. I cannot solve this matter. Its hard to explain so here is my code at first: <?php if ($_GET['section'] == 'gb' && (!isset($_REQUEST['senden']))) { $captcha = mt_rand(1,4); $_SESSION['C']=$captcha; } else { if (isset($_SESSION['C'])) { $captcha = $_SESSION['C']; } else { $_SESSION['C'] = mt_rand(1,4); $captcha = $_SESSION['C']; } } ?> <?php switch ($captcha) { case 1: ?><img src="include/captchasystem/pics/1.jpg"><?php break; case 2: ?><img src="include/captchasystem/pics/2.jpg"><?php break; case 3: ?><img src="include/captchasystem/pics/3.jpg"><?php break; case 4: ?><img src="include/captchasystem/pics/4.jpg"><?php break; } if (($_GET['section'] == 'gb' && (isset($_REQUEST['senden'])))) { $captcha = $_SESSION['C']; switch ($captcha) { case 1: { if (strtolower($_POST['form_captcha'])=='axzkds') { echo "nice one 1"; } } case 2: { if (strtolower($_POST['form_captcha'])=='krds7') { echo "nice one 2"; } } case 3: { if (strtolower($_POST['form_captcha'])=='pfpgh9') { echo "nice one 3"; } } case 4: { if (strtolower($_POST['form_captcha'])=='si99pl') { echo "nice one 4"; } } } if (isset($_REQUEST['senden'])) { unset($_SESSION['C']); $_GET['section'] = 'gb'; unset($_REQUEST['senden']); } } ?> I always tried to solve the problem, that when the user typed in the captcha wrong, a new capture appear. But then have the problem, that when the user then type in the right captcha, "it seems to be the wrong one". I think its because of the "if there is a $_SESSION['C'] write it in the variable $captcha"-rule. But without it, its impossible to compare Picturecaptcha and typedcaptcha. I dont have a plan to solve this Does anybody understand my problem and can help me? I only want to understand to solve this. Dont want to copy any captchasystem from anybody. Thx in Advance! Quote Link to comment https://forums.phpfreaks.com/topic/114852-captchasystem/ Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 your missing session_start(); at the start of the script.. also, captcha should create the images using GD, and not used static images Quote Link to comment https://forums.phpfreaks.com/topic/114852-captchasystem/#findComment-590606 Share on other sites More sharing options...
PdYpsilon Posted July 15, 2008 Author Share Posted July 15, 2008 I know I know.. This is actually a fragment of an inluded file. And the Mainfile has session_start of course, iam Sorry. I know that it is better to automatically create captchas. But that was not my question or problem! I want to know how to create a script, that shows a random picture, compare it with its ciphers and then, if the user typed it wrong, that a new random picture will be displayed and if THEN the user types in the right code THEN it should work. arrg... very hard to explain I see. Quote Link to comment https://forums.phpfreaks.com/topic/114852-captchasystem/#findComment-590634 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 i guess you could do something like <?php session_start(); if(!empty($_POST['cap']) && !empty($_SESSION['Who']) && $_post['cap'] == $_SESSION['Who']) { echo "WOOHOOO CORRECT"; } //Yes i know i could just append .jpg to the key. $input = array("Neo" => "neo.jpg", "Morpheus" => "morpheus.jpg", "Trinity" => "Trinity.jpg", "Cypher" => "Cypher.jpg", "Tank"=> "Tank.jpg"); $Who = array_rand($input); $WhoImg = $input[$Who]; $_SESSION['Who'] = $Who; echo "<img src=\"$randImg\">"; ?> Who is that ? <form method="post"> <input type="text" value="cap"> <input type="submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/114852-captchasystem/#findComment-590644 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.