corillo181 Posted February 7, 2008 Share Posted February 7, 2008 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89939-online-function/ Share on other sites More sharing options...
Daniel0 Posted February 7, 2008 Share Posted February 7, 2008 How doesn't it work? Are there any errors? Does the actual result differ from the expected result? Quote Link to comment https://forums.phpfreaks.com/topic/89939-online-function/#findComment-461313 Share on other sites More sharing options...
teng84 Posted February 8, 2008 Share Posted February 8, 2008 maybe if those function works altogether at once maybe you can add a main function that will call all your function so you only call all your function once.. Quote Link to comment https://forums.phpfreaks.com/topic/89939-online-function/#findComment-461444 Share on other sites More sharing options...
sennetta Posted February 9, 2008 Share Posted February 9, 2008 Add more comments - I always have a big block comment at the top saying exactly what the class does so that people don't have to decipher code. Also neaten the code a bit to make it more readable Quote Link to comment https://forums.phpfreaks.com/topic/89939-online-function/#findComment-462572 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.