PHP友情链接检测代码
笔记 2023-02-21 17:30:51 342 0 1

记录下php通过代码对友情链接检查,确认对方时候添加了本站的友情链接

<?php
$max_allow_links = 100; // 最大许可检查的链接数目
function my_file_get_contents($url, $timeout = 30) {
    if (function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $file_contents = curl_exec($ch);
        curl_close($ch);
    } else if (ini_get('allow_url_fopen') == 1 || strtolower(ini_get('allow_url_fopen')) == 'on') {
        $file_contents = @file_get_contents($url);
    } else {
        $file_contents = '';
    }
    return $file_contents;
}
function isExistsContentUrl($url, &$retMsg, $mydomain = "") {
    if (!isset($url) || empty($url)) {
        $retMsg = "填写的URL为空";
        return false;
    }
    if (!isset($mydomain) || empty($mydomain)) {
        $mydomain = $_SERVER['SERVER_NAME'];
    }
    $resultContent = my_file_get_contents($url);
    if (trim($resultContent) == '') {
        $retMsg = "未获得URL相关数据,请重试!";
        return false;
    }
    if (strripos($resultContent, $mydomain)) {
        $retMsg = "检测已经通过!";
        return true;
    } else {
        $retMsg = "请确认您已经添加本站的连接";
        return false;
    }
}
//调用试例
$result = "";
$ret = isExistsContentUrl("https://www.skyfinder.cc", $result, "wordpress.org");
if ($ret) {
    echo '通过检测:' . $result;
} else {
    echo "检测未通过:" . $result;
}
?>
friendlylinkcheck

您填写的所有信息都将进行加密

首页 主题 Api 友联