10.
Write
a PHP script to accept username and password. If in the first three chances,
username and password entered is correct, then display second form, otherwise
display error message.
Html Filen
<html>
<head>
<script>
function
getans()
{
st1=document.getElementById('txtname').value;
st2=document.getElementById('txtpass').value;
ob=new XMLHttpRequest();
if(ob)
alert("object created");
ob.onreadystatechange=function()
{
if(ob.readyState==4 &&
ob.status==200)
{
if(ob.responseText==3)
{
alert("sorry
you lost the chances to login");
location="error.html";
}
else
if(ob.responseText=="correct")
{
alert("you
entered correct details");
}
else
alert(ob.responseText);
}
}
ob.open("GET","slip10.php?n="+st1+"&p="+st2);
ob.send();
}
</script>
</head>
<body>
<input
type=text id=txtname placeholder="username"></br>
<input
type=password id=txtpass placeholder="password"></br>
<input
type="button" onclick="getans()" value="Login">
</body>
</html>
php file
<?php
$nm=$_GET['n'];
$ps=$_GET['p'];
if($nm==$ps)
{
echo "correct";
}
else
if(isset($_COOKIE['cnt']))
{
$x=$_COOKIE['cnt'];
$x=$x+1;
setcookie('cnt',$x);
echo $_COOKIE['cnt'];
if($_COOKIE['cnt']>=3)
setcookie('cnt',1);
}
else
{
setcookie('cnt',1);
echo
"1";
}
?>
No comments:
Post a Comment
Note: only a member of this blog may post a comment.