PHP uses curl to forge IP source code

Source: Internet
Author: User
    1. $ch = Curl_init ();
    2. $url = "http://localhost/target_ip.php";
    3. $header = Array (
    4. ' client-ip:58.68.44.61 ',
    5. ' x-forwarded-for:58.68.44.61 ',
    6. );
    7. curl_setopt ($ch, Curlopt_url, $url);
    8. curl_setopt ($ch, Curlopt_httpheader, $header);
    9. curl_setopt ($ch, curlopt_returntransfer,true);
    10. $page _content = curl_exec ($ch);
    11. Curl_close ($ch);
    12. echo $page _content;
    13. ?>
Copy Code

The requested target file---target_ip.php:

    1. echo getenv (' http_client_ip ');
    2. echo getenv (' http_x_forwarded_for ');
    3. echo getenv (' remote_addr ');
    4. ?>
Copy Code

Target file target_ip inside the IP print order is currently many open source system IP get sequential access fake_ip.php, see the result: 58.68.44.6158.68.44.61127.0.0.1

Finally, we provide two small examples. Example 1:

    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 ')); Constructing IP
    4. curl_setopt ($ch, Curlopt_referer, "http://bbs.it-home.org/"); Construction route
    5. curl_setopt ($ch, Curlopt_header, 1);
    6. $out = curl_exec ($ch);
    7. Curl_close ($ch);
    8. ?>
Copy Code

Example 2:

    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"];
    14. ?>
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.