corillo181 Posted September 18, 2007 Share Posted September 18, 2007 why is this class not working? it was working fine before i made it into a class , but i decided to make it a class and not is not doing anything. <?php class online{ var $remote; var $ref; var $uagen; var $on; var $db; var $sid; var $uid; function online($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(); } function setOnline($on){ $this->on = $on; if(!isset($this->on)){ $query = "INSERT INTO online(session_id,activity, ip_address, refurl, user_agent)VALUES('".$this->sid."','now()','".$this->remote."','".$this->ref."','".$this->uagent."')"; $this->db->query($query); setcookie('on','online',time()+300); return true; }elseif($this->on){ setcookie('on','online',time()+300); } } function setUser($uid){ $this->uid = $uid; if($this->uid){ $query = "UPDATE online SET activity=now(), member='y' WHERE session_id='".$this->sid."'"; $this->db->query($query); return true; } } function notOn(){ $maxtime = time() -600; $query = "DELETE FROM online WHERE UNIX_TIMESTAMP(activity) < '$maxtime'"; $this->db->query($query); return true; } } $_SESSION['user_id'] = 1; $remote = $_SERVER['REMOTE_ADDR']; $ref = $_SERVER['HTTP_REFERER']; $uagent = $_SERVER['HTTP_USER_AGENT']; $sid = session_id(); $on = $_COOKIE['on']; $uid = $_SESSION['user_id']; $online = new online($remote,$ref,$uagent,$sid); $online->setOnline($on); $online->setUser($uid); $online->notOn(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69710-online-class-help/ Share on other sites More sharing options...
Barand Posted September 18, 2007 Share Posted September 18, 2007 Give us a clue! What do you mean by "not working"? Quote Link to comment https://forums.phpfreaks.com/topic/69710-online-class-help/#findComment-350298 Share on other sites More sharing options...
corillo181 Posted September 18, 2007 Author Share Posted September 18, 2007 ok wheni test it is not inserting any record into the online table Quote Link to comment https://forums.phpfreaks.com/topic/69710-online-class-help/#findComment-350299 Share on other sites More sharing options...
corillo181 Posted September 19, 2007 Author Share Posted September 19, 2007 so i made the code smaller the profile is now when someone refresh the page i get this wraning Query Error: Duplicate entry '5bbaeaff2e1497490c0fb47946f6ccae' for key 1 <?php class online{ var $remote; var $ref; var $uagen; var $on; var $db; var $sid; var $uid; function online($r_add,$h_ref,$h_agent,$sid,$uid=NULL){ $this->remote = $r_add; $this->ref = $h_ref; $this->uagent = $h_agent; $this->sid = $sid; $this->db = new DB(); $this->uid = $uid; } function setOnline($on){ $this->on = $on; if(!isset($this->on)){ $query = "INSERT INTO online(session_id,activity, ip_address, refurl, user_agent)VALUES('".$this->sid."','now()','".$this->remote."','".$this->ref."','".$this->uagent."')"; $this->db->query($query); $_SESSION['on'] == 'online'; return true; }elseif($this->on && !$this->uid){ $query = "UPDATE online SET activity=now() WHERE session_id='".$this->sid."'"; $this->db->query($query); return true; } } } $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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69710-online-class-help/#findComment-351161 Share on other sites More sharing options...
chocopi Posted September 19, 2007 Share Posted September 19, 2007 Im guessing this is because you have no id field, and as it says you and not allowed duplicate entries. So all you need to do is add a id column at the beggining of your table and make sure it is primary and unique. That should solve it ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/69710-online-class-help/#findComment-351184 Share on other sites More sharing options...
corillo181 Posted September 19, 2007 Author Share Posted September 19, 2007 i know the reason now. after a few test i discover that the reason is becuase the session online is not been place so it keeps adding the entry because it doe snot find the session i try doing some changes, but nothing work. would any one know why is the session not taking place? Quote Link to comment https://forums.phpfreaks.com/topic/69710-online-class-help/#findComment-351194 Share on other sites More sharing options...
redarrow Posted September 19, 2007 Share Posted September 19, 2007 <?php ob_start(); session_start(); class online{ var $remote; var $ref; var $uagen; var $on; var $db; var $sid; var $uid; function online($r_add,$h_ref,$h_agent,$sid,$uid=NULL){ $this->remote = $r_add; $this->ref = $h_ref; $this->uagent = $h_agent; $this->sid = $sid; $this->db = new DB(); $this->uid = $uid; } function setOnline($on){ $this->on = $on; if(!isset($this->on)){ $query = "INSERT INTO online(session_id,activity, ip_address, refurl, user_agent)VALUES('".$this->sid."','now()','".$this->remote."','".$this->ref."','".$this->uagent."')"; $this->db->query($query); $_SESSION['on'] == 'online'; return true; }elseif($this->on && !$this->uid){ $query = "UPDATE online SET activity=now() WHERE session_id='".$this->sid."'"; $this->db->query($query); return true; } } } $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); ob_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69710-online-class-help/#findComment-351204 Share on other sites More sharing options...
corillo181 Posted September 19, 2007 Author Share Posted September 19, 2007 the session was not set Quote Link to comment https://forums.phpfreaks.com/topic/69710-online-class-help/#findComment-351216 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.