Gmail style chat user display online and offline concept - Mostlikers

04 September, 2013

Gmail style chat user display online and offline concept

This post i explain about  Gmail style chat user display online and offline concept . basically identify the chat user stay on online blink the green icon after user go on offline display the gray icon. so that concept i will explain this post just value pass in session using if and else statement to display the icon.


Create below format Table to connect the table on website

Insert the sample user and email id to the table. ex : Mostlikers, Mostlikers@gmail.com


index.php

Login and Logout image display on $_SESSION['login']="";  value will be empty display logout image else display on login image. login user name is correct value store on session else display incorrect msg. 

<?php
session_start();
$db = new mysqli('localhost', 'root', '', 'test'); // change the database
$_SESSION['login']="";
if(isset($_POST['submit']))
{
$email=$_POST['email'];
$check=$db->query("SELECT * FROM `chat` WHERE `email`='$email'");
$usrcheck=mysqli_num_rows($check);
if($usrcheck!="")
{
$descri=mysqli_fetch_object($check);
$_SESSION['login']=$descri->user;
}
else
{
echo "$email incorrect mail";

}
}
?>
<html>
<head>
<title>mostlikers</title>
<style type="text/css">
.box
{
margin:0 auto;
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:400px;
}
.user li { display:inline;
color:#666;
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
font-size:18px;
}

</style>
</head>
<body>
<form name="menu-form" class="box" method="post">
<label>Login Here</label>
<input type="email" name="email" title="menu" />
<input type="submit" name="submit" value="submit" />
<a href="logout.php">logout</a>
<p><img src="logout.png" width="15" height="12" /> Offline &nbsp;
<img src="login.png" width="15" height="12" /> Online </p>
</form>
<p>&nbsp;</p>
<ul class="user">
<li>
<?php
if($_SESSION['login']=="")
{
?>
<img src="logout.png" width="15" height="12" /> &nbsp;&nbsp User on offline
<?php
}
else
{
?>
<img src="login.png" width="15" height="12" />
<?php
}
?>
&nbsp;&nbsp; <?php echo $_SESSION['login']; ?></li>
</ul>
</body>
</html>

logout.php

<?php
session_start();
if(session_destroy())
{
header("Location:index.php");
}
?>


Icon


No comments:

Post a comment