Last active
August 10, 2017 07:29
-
-
Save Mauryashubham/d5ed1b693af4630f25f89dfc9673f3c8 to your computer and use it in GitHub Desktop.
Count Online Users Using PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.Make a file in notepad and save it as home.php and paste the below code. | |
<?php | |
//connect to mysql database | |
$con = mysqli_connect("localhost", "root", "", "test") or die("Error " . mysqli_error($con)); | |
$fetch="SELECT COUNT(*) FROM login WHERE LastTimeSeen > DATE_SUB(NOW(), INTERVAL 5 MINUTE)"; | |
$fet=mysqli_query($con, $fetch); | |
$online_row = mysqli_fetch_row($fet); | |
$online = $online_row[0]; | |
echo $online; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
@author : Shubham Maurya, | |
Email id : [email protected] | |
**/ | |
Hi all , Welcome to shubhammaurya.com , Today we are going to discuss , | |
how to Count Logged-In Users. | |
1.Make a file in notepad and save it as index.php and paste the below code. | |
<?php | |
//connect to mysql database | |
$con = mysqli_connect("localhost", "root", "", "test") or die("Error " . mysqli_error($con)); | |
if (isset($_POST['post'])) | |
{ | |
$name=$_POST['name']; | |
$pass=$_POST['pass']; | |
if($name=="admin" & $pass=="admin") | |
{ | |
$update="UPDATE login SET LastTimeSeen = NOW() where id=1"; | |
mysqli_query($con, $update); | |
header('location:home.php'); | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<form method="post"> | |
<input type="text" name="name"> | |
<input type="text" name="pass"> | |
<input type="submit" name="post"> | |
</form> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--1.Make a file in notepad and save it as login.sql and paste the below code. | |
-- phpMyAdmin SQL Dump | |
-- version 4.5.1 | |
-- http://www.phpmyadmin.net | |
-- | |
-- Host: 127.0.0.1 | |
-- Generation Time: Mar 21, 2017 at 02:48 PM | |
-- Server version: 10.1.19-MariaDB | |
-- PHP Version: 7.0.13 | |
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; | |
SET time_zone = "+00:00"; | |
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | |
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | |
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | |
/*!40101 SET NAMES utf8mb4 */; | |
-- | |
-- Database: `test` | |
-- | |
-- -------------------------------------------------------- | |
-- | |
-- Table structure for table `login` | |
-- | |
CREATE TABLE `login` ( | |
`id` int(11) NOT NULL, | |
`LastTimeSeen` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | |
-- | |
-- Dumping data for table `login` | |
-- | |
INSERT INTO `login` (`id`, `LastTimeSeen`) VALUES | |
(1, '2017-03-21 13:47:50'); | |
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | |
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | |
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment