"; if( $debug) { print_r($_GET); print_r($locations); } //print_r($_COOKIE); if( !file_exists( $cache_file)) { header( "location: http://ads.allsites.com/index.php"); } else { include( $cache_file); $array_name = "ad_$location"; $raw_data = $$array_name; // print_r($data); $next_link = false; $cookie_name = "ad_allsites_$location"; //echo "cookie_name=$cookie_name
"; if( isset( $_COOKIE[$cookie_name])) { $last_seen = intval($_COOKIE[$cookie_name]); } else $last_seen = false; //echo "last_seen=$last_seen
"; require_once( 'Mobile-Detect-master/Mobile_Detect.php'); $detect = new Mobile_Detect; $data = false; $is_mobile = false; if ( $detect->isMobile() ) { foreach( $raw_data as $index => $ad) { if(( $ad["wt"] > 0) && (strtolower($ad['arrayindex']) == 'mobile')) { $data[] = $ad; } } $is_mobile = true; if( $data === false) $data = $raw_data; if( $debug) print_r($data); /* $dt = date( "Y-m-d").".log"; $fp = fopen("mobile_logs/$dt","a"); fwrite( $fp, date( "H:i:s")."FORWARD: ". (array_key_exists( 'HTTP_X_FORWARDED_FOR', $_SERVER) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : ""). " - REMOTE: ". $_SERVER['REMOTE_ADDR'] . "\n"); fwrite( $fp, date( "H:i:s"). print_r($_SERVER,true)); fwrite( $fp, date( "H:i:s"). print_r($data,true)); if( $debug) echo date( "H:i:s")."FORWARD: ". (array_key_exists( 'HTTP_X_FORWARDED_FOR', $_SERVER) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : ""). " - REMOTE: ". $_SERVER['REMOTE_ADDR']."
"; fclose( $fp); */ } else { foreach( $raw_data as $index => $ad) { if(( $ad["wt"] > 0) && (strtolower($ad['arrayindex']) != 'mobile')) { $data[] = $ad; } } /* $dt = date( "Y-m-d").".log"; $fp = fopen("mobile_logs/$dt","a"); fwrite( $fp, date( "H:i:s")."not mobile\n"); if( $debug) echo date( "H:i:s")."no mobile
"; fclose( $fp); */ } $next_order = false; if( $last_seen === false) $next_order = 1; else { foreach( $data as $index => $ad) { if(( $last_seen == $ad["redirlink"]) && ($ad["wt"]>0)) { $next_order = $ad["display_order"]; if( $debug) echo "next_order = $next_order ct".count($data)."
"; ++$next_order; if( $debug) echo "next_order = $next_order
"; if( $next_order > count( $data)) $next_order = 1; if( $debug) echo "next_order = $next_order
"; break; } if( $next_order === false) $next_order = 1; } } if( $debug) echo "next_order = $next_order
"; foreach( $data as $index => $ad) { if( $debug) echo "display_order =". $ad['display_order']."
"; if(( $ad["display_order"] == $next_order) && ($ad["wt"] > 0)) { $next_seen = strval($ad["redirlink"]); if( $debug) echo "next_seen=$next_seen"; $next_link = $ad["ad"]; break; } } if(( $next_link === false) && ($data !== false)) { $ad = $data[0]; $next_seen = strval($ad["redirlink"]); $next_link = $ad["ad"]; } if( $next_link !== false) { setcookie( $cookie_name, $next_seen, time()+24*60*60); if($debug) echo "$cookie_name , $next_seen, ".strval(time()+24*60*60)."
"; if( array_key_exists(1,$locations)) { $next_link = str_replace( "PARAMONE",$locations[1], $next_link); } $return_code = " "; if( $debug){ print_r($_COOKIE); $return_code .= "
$next_link
"; $return_code .= ""; $return_code .=""; } else $return_code.= ""; $return_code .= " "; echo $return_code; } } ?>