Jump to content

Recommended Posts

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();

?>

Link to comment
https://forums.phpfreaks.com/topic/69710-online-class-help/
Share on other sites

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);
?>

Link to comment
https://forums.phpfreaks.com/topic/69710-online-class-help/#findComment-351161
Share on other sites

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 ;D

 

~ Chocopi

Link to comment
https://forums.phpfreaks.com/topic/69710-online-class-help/#findComment-351184
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/69710-online-class-help/#findComment-351194
Share on other sites

<?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();
?>

Link to comment
https://forums.phpfreaks.com/topic/69710-online-class-help/#findComment-351204
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.