Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Validating Captcha code using php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 476
    Comment on it

    Captcha verification includes:

    • should be a combination of alphanumeric characters.
    • should be case-sensitive
    • fresh captcha is to be displayed whenever a webpage is refreshed.
    • should be refreshed when user enters incorrect value.

     

    /* Simple program to validate the Captcha code in php */

     

    <?php
    error_reporting (0);
    session_start();
    
    
    if (isset($_POST["captcha"]) && !empty($_POST["captcha"])) {
    	if ($_SESSION["code"] == $_POST["captcha"]) {
    		echo "TEXT Matched!";
    	} else {
    		echo "Wrong TEXT Entered";
    	}
    }
    
    $varA=range("0","9");
    $varB=range("A","J");
    $varC=range("K","Z");
    $varD=range("a","j");
    $varE=range("k","z");
    
    $varArnd = array_rand($varA);
    $varBrnd = array_rand($varB);
    $varCrnd = array_rand($varC);
    $varDrnd = array_rand($varD);
    $varErnd = array_rand($varE);
    
    
    $captcha = $varA[$varArnd] . $varB[$varBrnd] . $varC[$varCrnd] . $varD[$varDrnd] . $varE[$varErnd];
    $_SESSION["code"] = $captcha;
    
    $prnt="<font color='red'>".$varA[$varArnd]."</font>"."<font color='green'>".$varB[$varBrnd]."</font>".$varC[$varCrnd].$varD[$varDrnd].$varE[$varErnd];
    
    ?>
    <html>
    <head>
    	<style type="text/css">
    	input{border:2px solid black;padding: 10px;border-radius: 5px}
    	label{font-size: 20px;font-weight: 600}
    	button{border:4px solid black;background-color: transparent;margin: 20px;font-size: 20px;font-weight: 600;color: black;border-radius: 5px;padding: 10px 20px}
    	</style>
    </head>
    <body style="padding:80px;background-color:#999;">
    	<form method="POST">
    		<table align="center">
    			<tr>
    				<td colspan="2" align="center" style="padding:10px">
    				<?php echo "<font size='20'>".$prnt."</font>";?>
    				</td>
    			</tr>
    			<tr>
    				<td><label>Enter the text:</label></td>
    				<td>
    					<input type="text" name="captcha" id="captcha">
    				</td>
    			</tr>
    			<tr>
    				<td colspan="2" align="center"><button id="button" value="submit">Submit</button></td>
    			</tr>		
    		</table>
    	</form>
    </body>
    </html>

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: