Home > Backend Development > PHP Tutorial > How to use CURL to forge IP source in PHP

How to use CURL to forge IP source in PHP

WBOY
Release: 2016-07-25 09:07:43
Original
915 people have browsed it
  1. $ch = curl_init();
  2. curl_setopt($ch, CURLOPT_URL, "http://localhost/2.php");
  3. curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:8.8.8.8', 'CLIENT-IP:8.8.8.8'));//IP
  4. curl_setopt($ch, CURLOPT_REFERER, "http://bbs.it-home.org/ "); //来路
  5. curl_setopt($ch, CURLOPT_HEADER, 1);
  6. $out = curl_exec($ch);
  7. curl_close($ch);
复制代码

2.文件 2.php

  1. function getClientIp() {
  2. if (!empty($_SERVER["HTTP_CLIENT_IP"]))
  3. $ip = $_SERVER["HTTP_CLIENT_IP"];
  4. else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
  5. $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  6. else if (!empty($_SERVER["REMOTE_ADDR"]))
  7. $ip = $_SERVER["REMOTE_ADDR"];
  8. else
  9. $ip = "err";
  10. return $ip;
  11. }
  12. echo "IP: " . getClientIp() . "";
  13. echo "referer: " . $_SERVER["HTTP_REFERER"];
复制代码

用1.php 请求 2.php,输出结果: IP:8.8.8.8 referer:http://bbs.it-home.org

伪造成功。



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template