Jump to content

Online users


graham23s

Recommended Posts

Hi Guys,

 

i was wondering the best way to show users online, my sessions setup is like:

 

logincheck.php

 

<?php
     include("includes/db_connection.php");
     include("includes/constants.php");
     
 $username = trim(strtolower(mysql_real_escape_string($_POST['username'])));
 $password = trim(strtolower(mysql_real_escape_string($_POST['password'])));	

  	 if (empty($username) || empty($password)) {	
  	 
 echo "Please fill in both fields.";
 exit;	

 }	

     // See if the details are in the database...
     $q = "SELECT `id`,`username`,`password` FROM `membership` WHERE `username`='$username'";
     $r = mysql_query($q);
     $row = mysql_fetch_array($r);

     //=====================================================================================//
     // Was there any results back...
     $any_results = mysql_num_rows($r);

 // was there a user found?...#######################################################
 if($any_results != 1) {	

     echo "Sorry username and password combination not found.";
     exit;	
     
 } else {	

     if(($any_results) > 0) {
     
     ## start the sessions ##############################################################

     session_start(); 
     
     $_SESSION['id'] = $row['id'];
     $_SESSION['username'] = $row['username'];
     $_SESSION['loggedin'] = 'yes'; 
     $_SESSION['member'] = $username;
     
     }	

 ## Update Login timer...############################################################
 $timer_query = "UPDATE `membership` SET `login`=now() WHERE `username`='$username' AND `password`='$password'";
 $timer_result = mysql_query($timer_query) or die (mysql_error());

     if ($timer_result) {	
     
 header("Location:myaccount.php"); 

     } 
         
     } 
?>

 

sessions.php

 

<?php
session_start(); 
header("Cache-control: private");
if($_SESSION['loggedin'] != 'yes') { 
    header("Location: login.php"); 
    exit; 
} 
$member = $_SESSION['member'];
?>

 

i was thinking ok an ENUM from No To Yes when the users logs in would that be a way to go or is there an easier way?

 

thanks guys

 

Graham

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/68488-online-users/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.