欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php curl伪造IP和来路

程序员文章站 2022-04-29 10:00:45
...
  1. $headers['CLIENT-IP'] = '202.103.229.40';
  2. $headers['X-FORWARDED-FOR'] = '202.103.229.40';
  3. $headerArr = array();
  4. foreach( $headers as $n => $v ) {
  5. $headerArr[] = $n .':' . $v;
  6. }
  7. ob_start();
  8. $ch = curl_init();
  9. curl_setopt ($ch, CURLOPT_URL, "http://localhost/curl/server.php");
  10. curl_setopt ($ch, CURLOPT_HTTPHEADER , $headerArr ); //构造IP
  11. curl_setopt ($ch, CURLOPT_REFERER, "http://bbs.it-home.org/ "); //构造来路
  12. curl_setopt( $ch, CURLOPT_HEADER, 1);
  13. curl_exec($ch);
  14. curl_close ($ch);
  15. $out = ob_get_contents();
  16. ob_clean();
  17. echo $out;
  18. ?>
复制代码

2,curl伪造IP和来路 服务端 server.php

  1. function GetIP(){
  2. if(!empty($_SERVER["HTTP_CLIENT_IP"]))
  3. $cip = $_SERVER["HTTP_CLIENT_IP"];
  4. else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
  5. $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  6. else if(!empty($_SERVER["REMOTE_ADDR"]))
  7. $cip = $_SERVER["REMOTE_ADDR"];
  8. else
  9. $cip = "无法获取!";
  10. return $cip;
  11. }
  12. echo "
    访问IP: ".GetIP()."
    ";
  13. echo "
    访问来路: ".$_SERVER["HTTP_REFERER"];
  14. ?>
复制代码

补充:$_SERVER['REMOTE_ADDR']无法伪造。