2025年02月27日 建站教程
因为ip被限制,无法正常的访问网站,那么如何利用php做不同虚拟ip访问网站呢?下面web建站小编带大家了解一下!
实现代码如下:
<?php function doCurl($url, $data=array(), $header=array(), $referer='', $timeout=30){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 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); $response = curl_exec($ch); if($error=curl_error($ch)){ die($error); } curl_close($ch); return $response; } // 调用 $url = 'http://www.example.com/server.php'; $data = array(); // 设置IP $header = array( 'CLIENT-IP: 192.168.1.100', 'X-FORWARDED-FOR: 192.168.1.100' ); // 设置来源 $referer = '设置访问网站域名'; $response = doCurl($url, $data, $header, $referer, 5); echo $response; ?>
本文链接:http://so.lmcjl.com/news/23974/