Jump to content

online function


corillo181

Recommended Posts

i asked this question is the normal php helo but i think i will get better help here since the people coming in here know to deal with classes in specific

my question is if anyone could modify thi class what you think i'm missing or doing wrong.

<?php
class online{
public $remote;
public $ref;
public $uagen;
public $on;
public $db;
public $sid;
public $uid;

public function __construct($r_add,$h_ref,$h_agent,$sid){
 $this->remote = $r_add;
 $this->ref = $h_ref;
 $this->uagent = $h_agent;
 $this->sid = $sid;
 $this->db = new DB();
}

/*
set the session of the members online.
$on = $_SESSON[''] user session identifier
$uid = user id if NULL is a guess
*/	
public function setOnline($on){
    $this->on = $on;


//get the time current time
	$time = time();

//check to see if the session is empty
	if(empty($this->on)){

// check to see if the session of this user was already in the database
		$query = "SELECT session_id FROM table WHERE session_id='{$this->sid}'";
		$result = $this->db->query($query);
		$count = $this->db->num_rows($result);

//if the session id is in the database the user closed the borswer and came back
//just add the session last 5 minutes
			if($count>0){
$_SESSION['on'] = 'online';

			}else{	

/*
if no session id in the database then add the user
set the session and update the new visitors table
*/
				$query = "INSERT INTO `table` (`session_id` ,`activity` ,`ip_address` ,`refurl` ,` user_agent`)VALUES ('{$this->sid}','$time','{$this->remote}','{$this->ref}','{$this->uagent}')";
			$this->db->query($query);

			$query2 = "UPDATE tra_visits SET count=(count+1)";
			$this->db->query($query2);
$_SESSION['on'] = 'online';

		}
	}
 }

/*
checks to see if the user has in id
not null a member
null = guest
*/
 public function setUser($uid=NULL){
 	$this->uid = $uid;
 	   if($this->uid){
	    $query = "UPDATE table SET activity='$time', member='y' WHERE session_id='".$this->sid."'";
	  	$this->db->query($query);
return true; 
	  }
 }

/*
updates a user field if exist everytim the user enters a new page.
*/
public function updateOnline($on){
	$time = time();
	  if($on=='online'){
	    $query = "UPDATE table SET activity='$time', refurl='{$this->ref}' WHERE session_id='{$this->sid}'";
	  	$result = $this->db->query($query);
	  }
}

/*
checks to see if a field is not active for more than 5 minutes
and deletes it.
*/
public function notOn(){
	$time = time();
	$query = "DELETE FROM table WHERE ('$time'-activity)>'500'";
	$this->db->query($query);
}
}

$remote = $_SERVER['REMOTE_ADDR'];
$ref = $_SERVER['HTTP_REFERER'];
$uagent = $_SERVER['HTTP_USER_AGENT'];
$sid = session_id();
$on = $_SESSION['on'];
$uid = $_SESSION['user_id'];

$online = new online($remote,$ref,$uagent,$sid);
$online->setOnline($on);
$online->setUser($uid);
$online->updateOnline($on);
$online->notOn();
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.