当前位置:Gxlcms > PHP教程 > phpcurl伪造IP和来路

phpcurl伪造IP和来路

时间:2021-07-01 10:21:17 帮助过:23人阅读

  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']无法伪造。

人气教程排行