MENU

采集自增长 包含页面id 和 typeid 自动更新和归零

January 12, 2020 • 已被 172 位童鞋围观过 • 代码分享

代码如下

<?php
//引入公共库
require_once(dirname(__FILE__)."/../../include/common.inc.php");
error_reporting(-1); 
$type[0]="windows";
$type[1]="mac";
$type[2]="linux";
$type[3]="google-android";
$type[4]="ios";
$type[5]="web-based";
$type[6]="security";
$type[7]="programming";
$type[8]="news";
$type[9]="entertainment";
$type[10]="productivity";
$type[11]="creative";
$type[12]="games";
$type[13]="social-media";
$type[14]="technology-explained";
$type[15]="buying-guides";
$type[16]="smart-home";
$type[17]="diy-projects";
$type[18]="product-reviews";

// 获取page 参数 然后 +1 保存 并自动升级栏目id
function Get_Type_page(){
    $file=dirname(__FILE__)."/page.cache";
    if(!file_exists($file)){
        file_put_contents($file,1);
    }
    $page=file_get_contents($file);
    $newpage=$page+1;
    if($newpage > 200){
        $newpage = 1;
        // 栏目ID+1
        UP_Type_id();
    }
    file_put_contents($file,$newpage);
    return $page;
}
// 获取栏目ID
function Get_Type_id(){
    $file=dirname(__FILE__)."/typeid.cache";
    if(!file_exists($file)){
        //栏目ID 从0开始
        file_put_contents($file,0);
    }
    $id=file_get_contents($file);
    return $id;
}
// 栏目ID+1 并在超出栏目id的时候 自动归0
function UP_Type_id(){
    $file=dirname(__FILE__)."/typeid.cache";
    if(!file_exists($file)){
        //栏目ID 从0开始
        file_put_contents($file,0);
        return 0;
    }
    $id=file_get_contents($file);
    $id=$id+1;
    if($id > 18){
        $id = 0;
    }
    file_put_contents($file,$id);
    return $id;
}


$page=Get_Type_page();
$name_id=Get_Type_id();
$name=$type[$name_id];

Last Modified: September 28, 2023