在php中要伪造IP和来源是很方便的事情,我们只要不超过10行代码即可实现,下面我来介绍利用php中curl函数来操作.
下面写个构造来路google.com代码,代码如下:
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, http:
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:8.8.8.8', 'CLIENT-IP:8.8.8.8'));
- curl_setopt($ch, CURLOPT_REFERER, "http://www.baidu.com/ "); //构造来路
- curl_setopt($ch, CURLOPT_HEADER, 1);
- $out = curl_exec($ch);
- curl_close($ch);
我们常用的获取ip来源的函数,代码如下:
- function getClientIp() {
- if (!emptyempty($_SERVER["HTTP_CLIENT_IP"]))
- $ip = $_SERVER["HTTP_CLIENT_IP"];
- else if (!emptyempty($_SERVER["HTTP_X_FORWARDED_FOR"]))
- $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
- else if (!emptyempty($_SERVER["REMOTE_ADDR"]))
- $ip = $_SERVER["REMOTE_ADDR"];
- else
- $ip = "err";
- return $ip;
- }
得出的结果是我们为造的IP地址来源.
- echo "<br>IP: " . getClientIp() . "";
- echo "<br>referer: " . $_SERVER["HTTP_REFERER"];
得出结果是我们的IP地址:8.8.8.8 来路 baidu.com 成功了吧. |