Simple way to use curl to forge IP in PHP _php tips

Source: Internet
Author: User
Tags curl http post

Curl Introduction:
Curl is a file transfer tool that uses URL syntax to work in a command-line manner. It supports many protocols: FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE, and LDAP. Curl also supports HTTPS authentication, HTTP POST method, HTTP put method, FTP upload, HTTP upload, proxy server, cookies, username/password Authentication, download file breakpoint, etc., the function is very powerful.
PHP Common Curl Implementation features:
1, the realization of remote access and collection of content
2, the implementation of PHP Web version of FTP upload download
3, the realization of analog landing
4, the implementation of interface docking (API), data transmission, etc.
5, the implementation of analog cookies, etc.

PHP uses the Curl feature
PHP does not support curl functionality by default, and you need to turn this feature on in php.ini

; extension= php_curl.dll//First remove the preceding semicolon, and restart Apache/iis 

Using Curl to forge IP

I found the IP copy into TXT file, and then sed and awk handled it and shared my awk processing script:

  BEGIN { 
    FS = ""; 
    Count = 0; 
    Iparr[count + +] = $ 
  #运行后 End 
    printf ("<?php\n"); 
    printf ("$iparr = array (\ n"); 
    for (i = 0; I < count i + +) { 
      printf ("'%s ' => '%s ', \ n ', Iparr[i], iparr[i]); 
    printf ("); \ n"); 

Curl use

  require_once dirname (__file__). "/iplib.php"; 
  $req _url = ""; 
  foreach ($iparr as $forward => $cip) { 
    $ch = Curl_init (); 
    curl_setopt ($ch, Curlopt_url, $req _url); 
    curl_setopt ($ch, Curlopt_httpheader, Array ( 
        "x-forwarded-for: $forward", 
        "Client-ip: $cip" 
    curl_setopt ($ch, Curlopt_referer, ''); 
    curl_setopt ($ch, Curlopt_header, 1); 
    Curl_exec ($ch); 
    Curl_close ($ch); 

Many servers are generally used $_server[' remote_addr ' to get the real IP of the client, this is the address in the transport layer has been decided, can not be modified through the curl, well, it seems that I did not help a friend to do the success of this matter, but still record

Related Article

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: 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.