You are on page 1of 2

<html>

<head>
<style type="text/css">
input{
border:1px solid olive;
border-radius:5px;
}
h1{
color:darkgreen;
font-size:22px;
text-align:center;
}
</style>
</head>
<body>
<h1>Login for student<h1>
<form action='#' method='post'>
<table cellspacing='5' align='center'>
<tr><td>User name:</td><td><input type='text' name='name'/></td></tr>
<tr><td>Password:</td><td><input type='password' name='pwd'/></td></tr>
<tr><td><img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchai
mg' ><br></td></tr>
<tr><td><label for='message'>Enter the code above here :</label><br></td></tr>
<tr><td><input id="6_letters_code" name="6_letters_code" type="text"><br></td></
tr>
<tr><td><small>Can't read the image? click <a href='javascript: refreshCaptcha()
;'>here</a> to refresh</small></td></tr>
<tr><td><input type='submit' name='submit' value='Submit'/></td></tr>
</table>
</form>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
var img = document.images['captchaimg'];
img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.ra
ndom()*1000;
}
</script>
<?php
if (!isset($_COOKIE['visits']))
{
$_COOKIE['visits'] = 0;
}
$visits = $_COOKIE['visits'] + 1;
setcookie('visits',$visits,time()+3600*24*365);
session_start();
if(isset($_POST['submit']))
{
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('abc') or die(mysql_error());
$name=$_POST['name'];
$pwd=$_POST['pwd'];
if($name!=''&&$pwd!='')
{

$query=mysql_query("select * from new where name='".$name."' and password='".


$pwd."'") or die(mysql_error());
$res=mysql_fetch_row($query);
if($res)
{
$_SESSION['name']=$name;
header('location:welcome.php');
}
else
{
echo'You entered username or password is incorrect';
}
}
else
{
echo'Enter both username and password';
}
if(empty($_SESSION['6_letters_code'] ) ||
strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0
)
{
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "\n The captcha code does not match!";
}
}
?>
<?php
if ($visits > 1)
{
echo("This is visit number $visits.");
}
else
{
// First visit
echo('Welcome to my Website! Click here for a tour!');
}
?>
</body>
</html>

You might also like