Block Bots/Robots From Registering on Your Website. Using This Simple Captcha Codes.
I know nobody would be happy seeing Bots flooding your site with spam post. Its very annoying. I've come up with some steps that'll help u stop them[bots].
You're free to ask any Question below..
Here We Go...
Copy The Below File And Save as captcha.php In Ur Public_html
Code:
session_start();
create_image();
exit();
function create_image()
{
$md5_hash = md5(rand(0,999));
$security_code = substr($md5_hash, 15, 5);
$_SESSION["security_code"] = $security_code;
$width = 100;
$height = 30;
$image = ImageCreate($width, $height);
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
ImageFill($image, 0, 0, $white);
ImageString($image, 5, 30, 6, $security_code, $black);
header("Content-Type: image/jpeg");
ImageJpeg($image);
ImageDestroy($image);
}
?>
now edit ur reg.php or registration.php or the file dat validate and execute ur reg form and look 4 this line of code
if(isset($_POST["submit"])){
immediately after it add dis
$code=$_POST["code"];
nw l
ook for The If or elseif statement that Check for the Inputed Value.
Add this Inclusive
Code:
if(!isset($_POST["code"])||$_POST["code"]==""||$_SESSION["security_code"]!=$_POST["code"])
{
//Your Error Message here.
}
Now Goto The Form field Area add dis Inclusive
Code:
Verification Code
Alternative Two
Save the Below Codes as img.php
Code:
session_start();
$code=rand(1000,9999);
$_SESSION["security_code"]=$code;
$im = imagecreatetruecolor(50, 24);
$bg = imagecolorallocate($im, 22, 86, 165);
$fg = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg);
imagestring($im, 5, 5, 5, $code, $fg);
header("Cache-Control: no-cache, must-revalidate");
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
follow Same Step Above to Integrate it at ur reg form
I.e
Enter Image Text
And Validate it like this,if U wish
if($_SESSION['security_code'] != $_POST['code']){
//error Message Here
}
Alternative Three
Save the Below Codes as image.php
Code:
header("Content-type: image/png");
$string = "abcdefghijklmnopqrstuvwxyz0123456789";
for($i=0;$i<6;$i++){
$pos = rand(0,36);
$str .= $string{$pos};
}
$img_handle = ImageCreate (60, 20) or die ("Cannot Create image");
//Image size (x,y)
$back_color = ImageColorAllocate($img_handle, 255, 255, 255);
//Background color RBG
$txt_color = ImageColorAllocate($img_handle, 0, 0, 0);
//Text Color RBG
ImageString($img_handle, 31, 5, 0, $str, $txt_color);
Imagepng($img_handle);
session_start();
$_SESSION['security_code'] = $str;
?>
follow The Above Methods
to integrate it also.
I.e.
and Validate it lyk dis if u wish
if(!isset($_POST["code"])||$_POST["code"]==""||$_SESSION["security_code"]!=$_POST["code"])
{
//Do you Error Mesage here
}
You're free to ask Questions
{{comment.anon_name ?? comment.full_name}}
{{timeAgo(comment.date_added)}}
{{comment.body}}
{{subComment.anon_name ?? subComment.full_name}}
{{timeAgo(subComment.date_added)}}
{{subComment.body}}