Hi V@no,
Thanks for your reply..
This is a new code added by me to record friends block hit.. Here is the code details..
function start_session($user_id = GUEST, $login_process = 0) {
global $site_db;
$this->user_info = $this->load_user_info($user_id);
if ($this->user_info['user_id'] != GUEST && !$login_process) {
if ($this->read_cookie_data("userpass") == $this->user_info['user_password'] && $this->user_info['user_level'] > USER_AWAITING) {
$this->set_cookie_data("userpass", $this->user_info['user_password']);
}
else {
$this->set_cookie_data("userpass", "", 0);
$this->user_info = $this->load_user_info(GUEST);
}
}
//if (!$login_process) {
$sql = "REPLACE INTO ".SESSIONS_TABLE."
(session_id, session_user_id, session_lastaction, session_location, session_ip)
VALUES
('".addslashes($this->session_id)."', ".$this->user_info['user_id'].", $this->current_time, '$this->user_location', '$this->user_ip')";
$site_db->query($sql);
//}
$this->session_info['session_user_id'] = $this->user_info['user_id'];
$this->session_info['session_lastaction'] = $this->current_time;
$this->session_info['session_location'] = $this->user_location;
$this->session_info['session_ip'] = $this->user_ip;
//**** added for recording friends referal ***************/
$hour = date('H');
if ($hour==0)
{
$sql = "UPDATE ".FRIENDS_TABLE." SET
`daily_visits`=0, `reset_flag`=0
WHERE `reset_flag`=1";
$site_db->query($sql);
}
if ($hour==1)
{
$sql = "UPDATE ".FRIENDS_TABLE." SET
`reset_flag`=1";
$site_db->query($sql);
}
$arr_dom = explode(".", $_SERVER['SERVER_NAME']);
if (count($arr_dom)>2)
{
if (strlen($arr_dom[count($arr_dom)-2])<=3 and strlen($arr_dom[count($arr_dom)-1])==2)
{
$domain_name = $arr_dom[count($arr_dom)-3].".".$arr_dom[count($arr_dom)-2].".".$arr_dom[count($arr_dom)-1];
}
else {
$domain_name = $arr_dom[count($arr_dom)-2].".".$arr_dom[count($arr_dom)-1];
}
}
else {
$domain_name = $arr_dom[0].".".$arr_dom[1];
}
$ref_url = parse_url(urldecode($_SERVER['HTTP_REFERER'])) ;
if ($ref_url==false) return false;
$ref_domain = str_replace("www.", "", $ref_url['host']);
if ($ref_domain=='') $ref_domain = $ref_url ;
if (strpos($ref_domain, $domain_name)===false)
{
$sql = "SELECT * FROM ".FRIENDS_TABLE." WHERE `url` REGEXP 'http(s)*://(([^/\.])*(/|\.){0,1}){0,1}$ref_domain(/){0,1}.*' ";
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);
$friend = array();
while ($row = $site_db->fetch_array($result)) {
if (preg_match("'http(s)*://(([^/\.])*([/|\.]){1}){0,1}".$ref_domain."(/){0,1}.*'i", $row['url'])==1)
{
$friend = $row;
}
}
if (count($friend)>0) {
$sql = "SELECT * FROM ".FRIENDS_REF_TABLE." WHERE
`ip`='".$_SERVER['REMOTE_ADDR']."'
AND `friend_id`='".$friend['id']."'
AND NOW()<DATE_ADD(`created`, INTERVAL 1 DAY) ";
$check_day = $site_db->query_firstrow($sql);
if (!$check_day)
{
$sql = "INSERT INTO ".FRIENDS_REF_TABLE." SET
`ip`='".$_SERVER['REMOTE_ADDR']."',
`host`='".gethostbyaddr($_SERVER['REMOTE_ADDR'])."',
`created`=NOW(),
`friend_id`='".$friend['id']."'
";
$site_db->query($sql);
$sql = "UPDATE ".FRIENDS_TABLE." SET
`total_visits`=`total_visits`+1,
`daily_visits`=`daily_visits`+1
WHERE `id`='".$friend['id']."'
";
$site_db->query($sql);
}
}
}
//**********************************************************
if ($this->user_info['user_id'] != GUEST) {
$this->user_info['user_lastvisit'] = (!empty($this->user_info['user_lastaction'])) ? $this->user_info['user_lastaction'] : $this->current_time;
$sql = "UPDATE ".USERS_TABLE."
SET ".get_user_table_field("", "user_lastaction")." = $this->current_time, ".get_user_table_field("", "user_location")." = '$this->user_location', ".get_user_table_field("", "user_lastvisit")." = ".$this->user_info['user_lastvisit']."
WHERE ".get_user_table_field("", "user_id")." = ".$this->user_info['user_id'];
$site_db->query($sql);
}
$this->set_cookie_data("lastvisit", $this->user_info['user_lastvisit']);
$this->set_cookie_data("userid", $this->user_info['user_id']);
return true;
}