Friday 2 August 2013

Step By Step Login Example In Php Mysql Using Session And Logout

Step By Step Login Example In Php Mysql Using Session And Logout


In this post we have create login page using php and mysql , we have used mysql_num_rows() for count the match rows. with this example i have also explain the database. if rows values is 0 then login is not valid and if rows value is 1 then user is valid. how to implement login and logout code in our project. below example explain how to do login and logout using php script.login example in php mysql using session and logout
 --------------------------------------------------------------------------------

database
--------------------------------------------------

login.php
------------------------------------------------

<?php
session_start();

if(isset($_GET['msg']))
{

    echo $_GET['msg'];
}


if(isset($_POST["submit"]))
{
$con=mysql_connect("localhost","root","");
mysql_select_db("project");

$sql="select * from registration where emailid='".$_POST['txtemail']."' and password='".md5($_POST['txtpass'])."' and status='a'";
$qsql=mysql_query($sql);

$nsql=mysql_num_rows($qsql);

if($nsql>=1)
{
   echo $_SESSION['user']=$_POST['txtemail'];
   ?>
   <script language="javascript">
   window.location="logout.php";
   </script>
   <?php
}

if($nsql <=0)
{
    echo "Not Valid user";
}
}

?>
<html>
<head>
</head>
<body>
<form method="post">
<table border="1">
<tr>
        <td>EmailId</td>
        <td><input type="text" name="txtemail" /></td>
</tr>

<tr>
        <td>Password</td>
        <td><input type="password" name="txtpass" /></td>
</tr>

<tr>
    <td><input type="submit" name="submit" value="Login" /></td>
    <td><input type="reset" name="reset" value="Cancle" /></td>
</tr>

</table>

</form>

</body>
</html>

logout.php

-------------------------------------------------

<?php
session_start();


if(isset($_SESSION['user']))
{
    unset($_SESSION['user']);
    $_SESSION['user']="";
?>
<script language="javascript">
//window.location="login.php?msg=You have logout successfully";
</script>
<?php   
}

?>

<a href="login.php?msg=You have logout successfully">logout</a>
Share This
Previous Post
Next Post

8 comments:

  1. this is very nice script..

    ReplyDelete
  2. hello sir.

    Step By Step Login Example in Php Mysql Using Session and Logout..
    this is very nice example.

    ReplyDelete
  3. php code with demo and database
    www.lessonwithdemo.com/268/php/create-photo-zoomer--in-php.php/

    ReplyDelete
  4. Very Useful In My Project...Thank you Sir....

    ReplyDelete
  5. Thank you.....Sir...Its very useful for my Project....

    ReplyDelete
  6. In Menu Study Material is not work

    ReplyDelete
  7. Wah sir Its very use full
    Thank You....

    ReplyDelete