Last active
October 11, 2017 03:37
-
-
Save mssoylu/477b548ece2567d674a53aa49070458e to your computer and use it in GitHub Desktop.
Captcha basit ornegi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// captcha.php | |
// Captcha image kaynagi dosyamiz resim olarak captcha kodu uretiyor | |
session_start(); | |
// Captcha yanlislikla onbellekten cagrilmasin diye header ayarlarini guncelliyoruz | |
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); | |
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); | |
header("Cache-Control: no-store, no-cache, must-revalidate"); | |
header("Cache-Control: post-check=0, pre-check=0", false); | |
header("Pragma: no-cache"); | |
function _rasgeleMetin($uzunluk=5) | |
{ | |
$_rand_src = array( | |
array(48,57) | |
, array(97,122) | |
// , array(65,90) | |
); | |
srand ((double) microtime() * 1000000); | |
$metin = ""; | |
for($i=0;$i<$uzunluk;$i++){ | |
$i1=rand(0,sizeof($_rand_src)-1); | |
$metin .= chr(rand($_rand_src[$i1][0],$_rand_src[$i1][1])); | |
} | |
return $metin; | |
} | |
$im = @imagecreatefromjpeg("captcha.jpg"); | |
$rand = _generateRandom(3); | |
$_SESSION['captcha'] = $rand; | |
ImageString($im, 5, 2, 2, $rand[0]." ".$rand[1]." ".$rand[2]." ", ImageColorAllocate ($im, 0, 0, 0)); | |
$rand = _generateRandom(3); | |
ImageString($im, 5, 2, 2, " ".$rand[0]." ".$rand[1]." ".$rand[2], ImageColorAllocate ($im, 255, 0, 0)); | |
Header ('Content-type: image/jpeg'); | |
imagejpeg($im,NULL,100); | |
ImageDestroy($im); | |
?> | |
<?php | |
// giris.php | |
// Giris kontrolumuz | |
if(!empty($_POST)) { | |
if(!isset($_SESSION['captcha']) || $_SESSION['captcha'] !== $_POST['captcha']) | |
throw new RuntimeException('captcha kontrol ediniz !'); | |
} | |
?> | |
<form role="form" method="post"> | |
<input type="text" name="username"> | |
<input type="password" name="password"> | |
<img src="captcha.php" alt="captcha image"></div> | |
<input type="text" name="captcha"> | |
<input type="submit" value="Giris"> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment