';print_r($_SERVER);echo''; header("Location: $DEFAULT_EXIT_URL"); flush(); exit; function getAppVarRotator($VAR,$dbr) { $query = "select value from irot_systemdata where var ='$VAR'"; $result=mysql_query($query,$dbr); if($row=mysql_fetch_object($result)) { return $row->value; } else { return 0; } } function getRotatorStatus($id,$dbr) { $query = "select rotator_id from irot_rotator where rotator_id=$id and status=1"; $result = mysql_query($query,$dbr); if(mysql_num_rows($result)>0) return TRUE; else return FALSE; } function getCurrentPriority($id,$dbr) { global $MAX_PRIORITY; $query="select priority_served from irot_rotator where rotator_id=$id"; $result = mysql_query($query,$dbr); $row = mysql_fetch_object($result); $priority_served = $row->priority_served; if($priority_served==0) return $MAX_PRIORITY; else return $priority_served; } function getCurrentPriorityHits($id,$dbr) { $query="select priority_hits from irot_rotator where rotator_id=$id"; $result = mysql_query($query,$dbr); $row = mysql_fetch_object($result); return $row->priority_hits; } function getCurrentServingStatus($id,$currentpriority,$currentpriorityhits,$dbr) { $query = "select * from irot_rotatorlinks where rotator_id=$id and priority = $currentpriority and counter< $currentpriority and is_served=0 and status=1 order by counter limit 0,1"; $result = mysql_query($query,$dbr); $numrows = mysql_num_rows($result); if($numrows>0) { $row=mysql_fetch_object($result); $link_id = $row->link_id; $targetURL = $row->targetURL; $counter = $row->counter; $query = "update irot_rotatorlinks set counter = counter + 1 where link_id = $link_id"; $updresult = mysql_query($query,$dbr); return $link_id; } else { $query = "update irot_rotatorlinks set counter = 0, is_served=1 where rotator_id = $rotator_id and priority = $currentpriority"; $updresult = mysql_query($query,$dbr); return findNextURLtoServe($id,$currentpriority,$currentpriorityhits,$dbr); } } function findNextURLtoServe($id,$currentpriority,$currentpriorityhits,$dbr) { global $MAX_PRIORITY,$MIN_PRIORITY; //This function should traverse through the available priorities other than the current priority and find a suitable link to display //Initialize the current priority links with counter = 0 and is_served = 0 $updquery = "update irot_rotatorlinks set is_served = 0, counter = 0 where rotator_id=$id and priority = $currentpriority"; $updresult = mysql_query($updquery,$dbr); //find the next available priority with links if($currentpriority > $MIN_PRIORITY) { $findquery = "select priority from irot_rotatorlinks where rotator_id=$id and priority < $currentpriority and status = 1 order by priority desc limit 0,1"; $findresult = mysql_query($findquery,$dbr); $findnumrows = mysql_num_rows($findresult); if($findnumrows>0) { $findobject = mysql_fetch_object($findresult); $priority = $findobject->priority; } else { $findquery = "select priority from irot_rotatorlinks where rotator_id=$id and status = 1 order by priority desc limit 0,1"; $findresult = mysql_query($findquery,$dbr); $findnumrows = mysql_num_rows($findresult); if($findnumrows>0) { $findobject = mysql_fetch_object($findresult); $priority = $findobject->priority; } else { return 0; } } } else { $priority = $MAX_PRIORITY; } $query = "select * from irot_rotatorlinks where rotator_id=$id and priority = $priority and counter< $priority and is_served=0 and status=1 order by counter limit 0,1"; $result = mysql_query($query,$dbr); $numrows = mysql_num_rows($result); if($numrows>0) { $row=mysql_fetch_object($result); $link_id = $row->link_id; $targetURL = $row->targetURL; $counter = $row->counter; $query = "update irot_rotatorlinks set counter = counter + 1 where link_id = $link_id"; $updresult = mysql_query($query,$dbr); $updquery = "update irot_rotator set priority_served = $priority where rotator_id=$id"; $updresult = mysql_query($updquery,$dbr); return $link_id; } return 0; } function getRotatorMode($id,$dbr) { $query = "select link_mode from irot_rotator where rotator_id=$id"; $result = mysql_query($query,$dbr); $row = mysql_fetch_object($result); return $row->link_mode; } function recordHitsStats($rotator_id,$URL_SERVED,$link_mode,$IPADDRESS,$REFERRER,$HIT_DATE,$HIT_TIME,$dbr) { $RETURN_URL = getAppVarRotator("VarDefaultURL",$dbr); $getquery = "select targetURL from irot_rotatorlinks where rotator_id=$rotator_id and link_id=$URL_SERVED"; $getresult=mysql_query($getquery,$dbr); if(mysql_num_rows($getresult)>0) { $getrow=mysql_fetch_object($getresult); $targetURL = $getrow->targetURL; } else { return $RETURN_URL; } if($targetURL) { $insertquery="insert into irot_hits_stats (rotator_id,link_id,hit_date,hit_time,referrer,ipaddress) values ('$rotator_id',$URL_SERVED,'$HIT_DATE','$HIT_TIME','$REFERRER','$IPADDRESS')"; mysql_query($insertquery,$dbr); $updatequery = "update irot_rotator set hits_till_date = hits_till_date + 1 where rotator_id=$rotator_id"; mysql_query($updatequery,$dbr); } return $targetURL; } function getCurrentServingStatusByCreateDate($id,$dbr) { $query = "select link_id from irot_rotatorlinks where rotator_id=$id and is_served=0 and status = 1 order by create_date ASC limit 0,1"; $result = mysql_query($query,$dbr); $numrows = mysql_num_rows($result); if($numrows > 0) { $row = mysql_fetch_object($result); $link_id = $row->link_id; $updquery = "update irot_rotatorlinks set is_served = 1 where link_id = $link_id and rotator_id=$id"; $updresult = mysql_query($updquery,$dbr); return $link_id; } else { $updquery = "update irot_rotatorlinks set is_served = 0 where rotator_id = $id"; $updresult = mysql_query($updquery,$dbr); $query = "select link_id from irot_rotatorlinks where rotator_id=$id and is_served=0 and status = 1 order by create_date ASC limit 0,1"; $result = mysql_query($query,$dbr); $numrows = mysql_num_rows($result); if($numrows > 0) { $row = mysql_fetch_object($result); $link_id = $row->link_id; $updquery = "update irot_rotatorlinks set is_served = 1 where link_id = $link_id and rotator_id=$id"; $updresult = mysql_query($updquery,$dbr); return $link_id; } } return 0; } function getPriorityBasedURL($id,$dbr) { $sql = "select * from irot_rotatorlinks where status=1 and rotator_id=$id and is_served = 0 and counter < priority order by priority desc, counter asc limit 0,1"; $result = mysql_query($sql,$dbr); if(mysql_num_rows($result)>0) { $row=mysql_fetch_object($result); $link_id = $row->link_id; $targetURL = $row->targetURL; $counter = $row->counter; $priority = $row->priority; $chkcounter = ($counter+1); if($chkcounter>=$priority) { $query = "update irot_rotatorlinks set counter = counter + 1, is_served=1 where link_id = $link_id"; $updresult = mysql_query($query,$dbr); } else { $query = "update irot_rotatorlinks set counter = counter + 1 where link_id = $link_id"; $updresult = mysql_query($query,$dbr); } return $link_id; } else { $sql = "update irot_rotatorlinks set counter = 0, is_served =0 where rotator_id = $id"; $updresult = mysql_query($sql,$dbr); $sql = "select * from irot_rotatorlinks where status=1 and rotator_id=$id and is_served = 0 and counter < priority order by priority desc, counter asc limit 0,1"; $result = mysql_query($sql,$dbr); if(mysql_num_rows($result)>0) { $row=mysql_fetch_object($result); $link_id = $row->link_id; $targetURL = $row->targetURL; $counter = $row->counter; $priority = $row->priority; $chkcounter = ($counter+1); if($chkcounter>=$priority) { $query = "update irot_rotatorlinks set counter = counter + 1, is_served=1 where link_id = $link_id"; $updresult = mysql_query($query,$dbr); } else { $query = "update irot_rotatorlinks set counter = counter + 1 where link_id = $link_id"; $updresult = mysql_query($query,$dbr); } return $link_id; } else { return 0; } } } ///************************** function class's code ********************************/ function getIpArray() { $tmp = array(); if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && strpos($_SERVER['HTTP_X_FORWARDED_FOR'],',')) { $tmp += explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']); } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $tmp[] = $_SERVER['HTTP_X_FORWARDED_FOR']; } $tmp[] = $_SERVER['REMOTE_ADDR']; return $tmp; } function getIp() { global $IP_PRIVATE_LIST_SAFE; $ip = "unknown"; $ip_array=getIpArray(); foreach ( $ip_array as $ip_s ) { if( $ip_s!="" AND !isIPInNetArray($ip_s,$IP_PRIVATE_LIST_SAFE)) { $ip=$ip_s; break; } } return($ip); } //This function check if a ip is in an array of nets (ip and mask) function isIpInNetArray($theip,$thearray) { $exit_c=false; foreach ( $thearray as $subnet ) { list($net,$mask)=split("/",$subnet); if(isIPInNet($theip,$net,$mask)) { $exit_c=true; break; } } return($exit_c); } //Determine if an ip is in a net. //E.G. 120.120.120.120 in 120.120.0.0/16 //I saw this in another post in this site but don't remember where :P function isIPInNet($ip,$net,$mask) { $lnet=ip2long($net); $lip=ip2long($ip); $binnet=str_pad( decbin($lnet),32,"0","STR_PAD_LEFT" ); $firstpart=substr($binnet,0,$mask); $binip=str_pad( decbin($lip),32,"0","STR_PAD_LEFT" ); $firstip=substr($binip,0,$mask); return(strcmp($firstpart,$firstip)==0); } //*******************************************************************************/ ?>