首页站内杂志技术文摘
文章内容页

php实现友链自动检测

  • 作者:雨祺
  • 来源: 原创
  • 发表于2023-11-16 20:17:24
  • 阅读0
  • php实现友链自动检测。此教程主要是为了方便在后台友情能及时查看友情链接是否正常!极大的方便了检测与节省时间!现在小编开始进入正题讲究教程方法!其实非常简单,定义一个函数即可完成!函数如下:
    1. <?php 
    2.             $max_allow_links = 100; // 最大许可检查的链接数目 
    3.             function my_file_get_contents($url, $timeout = 30) { 
    4.                 if (function_exists('curl_init')) { 
    5.                     $ch = curl_init(); 
    6.                     curl_setopt($ch, CURLOPT_URL, $url); 
    7.                     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    8.                     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
    9.                     $file_contents = curl_exec($ch); 
    10.                     curl_close($ch); 
    11.                 } else if (ini_get('allow_url_fopen') == 1 || strtolower(ini_get('allow_url_fopen')) == 'on') { 
    12.                     $file_contents = @file_get_contents($url); 
    13.                 } else { 
    14.                     $file_contents = ''
    15.                 } 
    16.                 return $file_contents; 
    17.             } 
    18.             function isExistsContentUrl($url, &$retMsg, $mydomain = "") { 
    19.                 if (!isset($url) || empty($url)) { 
    20.                     $retMsg = "配置URL为空"
    21.                     return false
    22.                 } 
    23.                 if (!isset($mydomain) || empty($mydomain)) { 
    24.                     $mydomain = $_SERVER['SERVER_NAME']; 
    25.                 } 
    26.                 $resultContent = my_file_get_contents($url); 
    27.                 if (trim($resultContent) == '') { 
    28.                     $retMsg = "网站无法访问"
    29.                     return false
    30.                 } 
    31.                 if (strripos($resultContent, $mydomain)) { 
    32.                     $retMsg = "友链正常"
    33.                     return true
    34.                 } else { 
    35.                     $retMsg = "未添加本站"
    36.                     return false
    37.                 } 
    38.             } 
    39.         ?> 
    【审核人:站长】

        标题:php实现友链自动检测

        本文链接:https://www.wenyunfang.com/zazhi/zhongwangjiaocheng/251.html

        赞一下

        深度阅读

        • 您也可以注册成为文韵坊的作者,发表您的原创作品、分享您的心情!

        阅读记录

          关注文韵坊