Tuesday, 9 June 2020

how to do captch entry in ur form

how to do captch entry in ur form
using captcha entry, u can avoid hackers who is try to login online directly
ist we have to crate a page script, then we can access that page
generate.php
<?php
session_start(); session is started
$text = $_SESSION['secure']; load the data to session variable like attributes
$t_size =30; load the data to session variable like attributes
$im_width = 110;
$im_height =40;
$image = imagecreate($im_width, $im_height); create image using width and height
$bg = imagecolorallocate($image, 255,255,255); background color
$t_color = imagecolorallocate($image, 0,0,0); text color
for ($x=1; $x<=30; $x++){
$x1 = rand(1, 100); using this creaate lines , u have doubt, it will not  unique for this 4 rand, it will diffferent lines
$y1 = rand(1, 100);
$x2 = rand(1, 100);
$y2 = rand(1, 100);
 
imageline($image, $x1, $y1, $x2, $y2, $t_color); craete image lines  In a random
}
 
//random not prints every one as unique, it will prints some irregular
imagettftext($image, $t_size, 0, 15, 30, $t_color, 'C:\xampp\htdocs\vamis\lesson53\OpenSans-Bold.ttf',$text ); create captcha using this
imagejpeg($image); create in jpeg format
imagedestroy($image); destroy that image
 
?>
index.php
http://localhost/vamis/lesson53/index.php
<?php
session_start();
 
if (!isset($_POST['code']) ) { if form is submitte
  d
$_SESSION['secure'] =  rand(99, 999); load that random number to this variable
 
 
 
}
else{
if($_SESSION['secure'] == $_POST['code']){ if that loaded number is equal to that enter number
$op = 'correct'; it is correct
}
else { otherwise it is incorrect
$op = 'incorrect, try again';
}
}
 
?>
<br>
<img src="generate.php" />
 
<br><br>
 
<form action="index.php" method ="post"> post to indexphp page
security code: <input type = "text" size="6" name ="code">
<input type ="submit" value="submit">
</form>
<div> <?php if(isset($op)){echo $op;} ?></div> if op is submmited, print that













how to start the session session_start
how to create the session and store the data to session variable $_SESSION['secure'];
how to cerete the image imagecreate
how to apply text to image and font imagecolorallocate
how to create random numbers rand
why if rand is serial, why their numbers are not same
how to create lines on image imageline
how to create captcha imagettftext
imagejpeg
imagedestroy
will I write  session_start
how to check it is submiited or not isset
how to create arandom number and how to store that in random rand
$_SESSION['secure']
how to chccek sumbitted and generated number is right or wrong if elses
else




No comments:

Post a Comment