xsubs Posted October 30, 2007 Share Posted October 30, 2007 I tried to build a security code, i think i succeed, but it doesn't work well. I mean, sometimes it works and redirect you, and sometime it just refresh the page (i dont know why!), and there is no response. This is my code: <link rel="stylesheet" type="text/css" href="http://www.extremesubs.org/Functions/style.css"> <?php function createImage(){ if (!isset($_COOKIE['AiSC'])) { $fileName = md5(rand(100000,999999)); $Text = rand(1000,9999); $CreatePic = imagecreatetruecolor(150, 43); $White = imagecolorallocate($CreatePic, 255, 255, 255); imagefilledrectangle($CreatePic, 0, 0, 700, 200, $White); $Color = imagecolorallocate($CreatePic, rand(0,200), rand(0,200), rand(0,200)); $font = 'arialbd'; $angle = rand(-5,6); // Adds the text imagettftext($CreatePic, 20, $angle, 30, 33, $Color, $font, $Text); $Output= "pictures/$fileName.gif"; imagegif($CreatePic,$Output); setcookie("AiSC", $Text, time()+1200, "/"); setcookie("AiSCT", $Output, time()+1200, "/"); return $Output; } else { return $_COOKIE['AiSCT']; } } // Checks if equal if (isset($_POST['send'])) { if ($_POST['code'] == $_COOKIE['AiSC']) { unlink($_COOKIE['AiSCT']); setcookie("AiSC", $Text, time()-1200, "/"); setcookie("AiSCT", $Output, time()-1200, "/"); echo "<script language='JavaScript'>window.location=('Download.php?id=".$_GET['id']."');</script>"; } else { echo "<script language=\"JavaScript\">alert(\"קוד האבטחה שהקשת אינו זהה לקוד המקורי.\");</script>"; } } ?> <form action="" method="post" name="SecurityCodeForm" enctype="multipart/form-data"> <div align="center" style="font-family:arial;font-weight:bold;font-size:12px;color:black;direction:rtl;" class="Security"> הקלד בבקשה את הטקסט שבתיבה, ולאחר מכן לחץ על "הורד".<br> <table border="0" celspacing="0" style="height:45;"> <tr> <td> <img src="<?=createImage();?>"> </td> <td> <input type="text" name="code" style="font-family:arialbd;font-size:20px;font-color:black;width:150px;height:45px;direction:ltr;vertical-align:baseline;"> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="send" style="font-family:arialbd;font-size:12px;font-color:black;width:100px;height:25px;direction:ltr;vertical-align:baseline;" class="InputButton" value="הורד תרגום"> </table> </form> What can i change to make it work better? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/75334-security-code-problem/ Share on other sites More sharing options...
xsubs Posted October 31, 2007 Author Share Posted October 31, 2007 Please!!! Quote Link to comment https://forums.phpfreaks.com/topic/75334-security-code-problem/#findComment-381698 Share on other sites More sharing options...
purefan Posted October 31, 2007 Share Posted October 31, 2007 hmmm... would you mind telling what is it supposed to do? Quote Link to comment https://forums.phpfreaks.com/topic/75334-security-code-problem/#findComment-381711 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 instead of if (isset($_POST['send'])) { if ($_POST['code'] == $_COOKIE['AiSC']) { try if (isset($_POST['code'])) { if ($_POST['code'] == $_COOKIE['AiSC']) { Quote Link to comment https://forums.phpfreaks.com/topic/75334-security-code-problem/#findComment-381738 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 the above should work the problem would be if the user hits enter in the code box then the submit value does not come in, it only comes when you click on submit Quote Link to comment https://forums.phpfreaks.com/topic/75334-security-code-problem/#findComment-381742 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.