PHP How to Curl fake IP and source implementation program

Source: Internet
Author: User
Tags curl urlencode

Curl is not enabled by default, enabling methods.

Enable CURL settings


If you are under the Windows platform, then it is very simple, you need to change your php.ini file settings, find Php_curl.dll, and cancel the previous semicolon comment on the line. As shown below:

Cancel the comment below

The code is as follows Copy Code

Extension=php_curl.dll

If you are under Linux, then you need to recompile your PHP, edit, you need to open the compilation parameters--The Configure command on the "–with-curl" parameter.

Simple test Instance

The code is as follows Copy Code

<?php
Initializes a CURL object
$curl = Curl_init ();

Set the URL you want to crawl
curl_setopt ($curl, Curlopt_url, ' http://coolshell.cn ');

Set Header
curl_setopt ($curl, Curlopt_header, 1);

Sets the curl parameter to require that the results be saved to the string or to the screen.
curl_setopt ($curl, Curlopt_returntransfer, 1);

Run Curl, request Web page
$data = curl_exec ($curl);

Close URL Request
Curl_close ($curl);

Show the data you get
Var_dump ($data);

Imitate post data

  code is as follows copy code

<?php
$phoneNumber = ' 13912345678 ';
$message = ' This is generated by curl and PHP ';
$curlPost = ' pnumber= '. UrlEncode ($phoneNumber). ' &message= '. UrlEncode ($message). ' &submit=send ';
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, ' http://www.example.com/sendSMS.php ');
curl_setopt ($ch, Curlopt_header, 1);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_postfields, $curlPost);
$data = Curl_exec ();
Curl_close ($ch);
?>

Now get to the point where Curl fake IP and source

1.php Code:

The code is as follows Copy Code

$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, "http://localhost/2.php");
curl_setopt ($ch, Curlopt_httpheader, Array (' x-forwarded-for:8.8.8.8 ', ' client-ip:8.8.8.8 '));//ip
curl_setopt ($ch, Curlopt_referer, "http://www.111cn.net/"); Antecedents
curl_setopt ($ch, Curlopt_header, 1);
$out = curl_exec ($ch);
Curl_close ($ch);

2.php Code:

  code is as follows copy code
function Getclientip () {
    if (!empty ($_server[) http_client _ip "])
        $ip = $_server[" Http_client_ip "];
    Else if (!empty ($_server["http_x_forwarded_for"]))
        $ip = $_server["http_x _forwarded_for "];
    Else if (!empty ($_server["REMOTE_ADDR"))
        $ip = $_server["REMOTE_ADDR"];
    Else
        $ip = "err";
    return $ip;
}
Echo "IP:". Getclientip (). "";
echo "Referer:". $_server["Http_referer"];

1.php request 2.php, output result:

As for SSL, the HTTPS protocol, you just have to turn the http://in the Curlopt_url connection into https://. Of course, there is also a parameter called Curlopt_ssl_verifyhost can be set to verify the site.

For cookies, you need to know the following three parameters:

Curlopt_cookie, set a COOKIE in your face-to-face session
Curlopt_cookiejar, save a cookie when the session ends
Curlopt_cookiefile,cookie's file.

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.