0

我创建了一个快速简单的会员推荐脚本来检查会员 ID,如果这是一个注册 ID,它将检查数据库中它来自的 IP,如果它不在列表中,它将奖励会员 1 分.

但是,当我检查超过 30 个不同 IP 地址的测试版本时,并非所有 IP 地址都已存储,并且似乎在某个时间点后停止保存它们。

该数据库只是一个常规的 mysql 数据库。

您将如何存储 IP 和奖励附属公司?

编辑:代码

function awardAffiliate() {
global $wpdb;

//get the affliateID from the url. 
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 
$affiliateID = basename(parse_url($url,  PHP_URL_PATH));


//get the IP address. 
$ipAddress = $_SERVER['REMOTE_ADDR'];
/


$checkAffiliate = $wpdb->get_results( $wpdb->prepare("SELECT user_id, user_count FROM affiliate_members WHERE user_id = '$affiliateID'"));

foreach ($checkAffiliate as $affiliate) { 

    $regAffiliateID = $affiliate->user_id;
    $regAffiliateCount = $affiliate->user_count;
}

// ammend them so that the count is +1 and the ip address is pushed into the array. add ',' before new ipaddress

$newCount = $regAffiliateCount + 1;


$updateffiliate = $wpdb->get_results( $wpdb->prepare("UPDATE affiliate_members SET user_count = '$newCount' WHERE user_id = '$affiliateID'"));

$checkIpaddresses = $wpdb->get_results( $wpdb->prepare("SELECT affiliateID, source FROM affiliate_ip WHERE affiliateID = '$affiliateID'"));

foreach ($checkIpaddresses as $ipaddress) { 
    $ipSource = $ipaddress->source;
}


$addIP = "," .$ipAddress;
$ipSource .= $addIP;

$updateIpAddress = $wpdb->get_results( $wpdb->prepare("UPDATE affiliate_ip SET source = '$ipSource' WHERE affiliateID = $affiliateID"));

}

4

0 回答 0