How to do a Login Page in Php [Resolved]

Posted by Kundan under Others on 9/16/2013 | Points: 10 | Views : 4689 | Status : [Member] | Replies : 2
Dear all,
Iam new to php.How to do a Login Page in Php.




Responses

Posted by: Satyapriyanayak on: 9/16/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
config.php


<?php

/* Database Connection */

$sDbHost = 'localhost';
$sDbName = 'onlinetest';
$sDbUser = 'root';
$sDbPwd = '';

$dbConn = mysql_connect ($sDbHost, $sDbUser, $sDbPwd) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($sDbName,$dbConn) or die('Cannot select database. ' . mysql_error());

?>

Login.php

<?php
session_start();
include("config.php");
if($_REQUEST["btn_login"]=="submit")
{
$uname=$_POST["txt_login"];
$password=$_POST["txt_pwd"];
$sql="select * from user where user='".$uname."' and password='".$password."'";
//echo $sql;
//exit;
$res=mysql_query($sql);
if($rs=mysql_num_rows($res)>0)
{
$_SESSION["uname"]=$uname;
//echo $_SESSION["uname"];
//exit;
//echo $rs;
//exit;
echo "<script>location.href='welcome.php'</script>";
}
else
{
echo "<script>location.href='Login.php?qs=invalid'</script>";
}
}
?>
<script language="javascript" type="text/javascript">
function validate()
{
if(document.frm_login.txt_login.value=="")
{
alert("please Enter your user name");
document.frm_login.txt_login.focus();
return false;
}
if(document.frm_login.txt_pwd.value=="")
{
alert("please Enter your password");
document.frm_login.txt_pwd.focus();
return false;
}
return true;
}
</script>
<form name="frm_login" method="POST" action="Login.php" onSubmit="return validate();">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" width="100%" align="center"><br><br><b><font size=3>LOGIN FORM</font></b>&nbsp;
<p>&nbsp;</p>
</tr>
<tr>
<td width="25%" align="center"><img src="img/key_img.jpg"></td>
<td width="75%" height="200">
<table border="0" width="100%" cellpadding="4">
<tr>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td colspan="2" align="center"><font color="#EB3C37"></font></td>
</tr>
<tr>
<td colspan="2" align="center"><br></td>
</tr>
<?php

if($_REQUEST["qs"]=="invalid")
{
echo "<strong>Invalid Username or Password</strong>";
}
?>
<tr>
<td width="30%" align="right">Username:</td>
<td width="70%"><input type="text" name="txt_login"></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="password" name="txt_pwd"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="btn_login" value="submit"></td>
</tr>
</table>
<tr>
<td>&nbsp;</td>
</tr>
</td>
</tr>
</table>
</form>

welcome.php

<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Welcome</title>
</head>

<body>
<form action="welcome.php" method="get" name="welcome">
<?php echo '<b>Welcome:</b>'.$_SESSION["uname"]; ?>
</form>
</body>
</html>


If this post helps you mark it as answer
Thanks

Kundan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/16/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Satyapriyanayak

I have IE,Mozila and Dotnet Environment how to run this?


Mark as Answer if its helpful to you

Kundan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response