对于限制了 ip 和来源的网站,使用正常的访问方式是无法访问的。
偶然看到的一种方法,记下了(๑•̀ㅁ•́ฅ)
使用 php 的 curl 类实现模拟 ip 和来源,访问那些限制了 ip 和来源的网站。

设置限制页面 server.php

<?php
$get_ip = getip();//获取访问者ip
$referer = getreferer();//获取访问者来源

$allow_ip = '172.1.1.1';//设置指定IP用户
$allow_referer = 'https://www.lykep.com/';//设置指定来源用户

if($get_ip==$allow_ip && strpos($referer, $allow_referer)===0){
    echo 'Welcome from https://www.lykep.com/ the friend';
}else{
    echo 'Welcome '.getreferer()." friend";
}

//获取访问者ip
function getip(){
    if(!empty($_SERVER['HTTP_CLIENT_IP'])){
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }elseif(!empty($_SERVER['REMOTE_ADDR'])){
        $ip = $_SERVER['REMOTE_ADDR'];
    }else{
        $ip = '';
    }
    return $ip;
}

//获取访问者来源
function getreferer(){
    if(isset($_SERVER['HTTP_REFERER'])){
        return $_SERVER['HTTP_REFERER'];
    }
    return '';
}

?>

使用 curl 模拟 ip 和来源进行访问

<?php
function startCurl($url, $data=array(), $header=array(), $referer, $timeout){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//模拟IP
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    // 模拟来源
    curl_setopt($ch, CURLOPT_REFERER, $referer);
    $result = curl_exec($ch);
    if($error=curl_error($ch)){
        die($error);
    }
    curl_close($ch);
    return $result;
}
//调用
$url = 'http://xx.xx/server.php';
$data = array();
//设置IP
$header = array(
    'CLIENT-IP: 172.1.1.1',
    'X-FORWARDED-FOR: 172.1.1.1'
);
//设置来源
$referer = 'https://www.lykep.com/';
//开始执行
$result = startCurl($url,$data,$header,$referer,5);
echo $result;
?>

如果提示SSL错误可以参考:https://www.cnblogs.com/sdgf/p/6202131.html

最后修改:2019 年 09 月 19 日
如果觉得我的文章对你有用,请随意赞赏