Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/75334-security-code-problem/
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.