Using Curl to simulate IP instances

Source: Internet
Author: User
For websites that have restricted IP and sources, it is not possible to use normal acquisition methods. This article will introduce a method that uses the PHP Curl class to achieve analog IP and source, and to capture websites that limit IP and source.

1. Set page limit IP and source access

server.php

<?php $client _ip = GetIP (); $referer = Getreferer (); $allow _ip = ' 192.168.1.100 '; $allow _referer = ' http://www.uxuew.cn '; if ($client _ip== $allow _ip && strpos ($referer, $allow _referer) ===0) {  echo ' Allow access ';} else{  echo ' Deny Access ';}  Get visitor ipfunction GetIP () {  if (!empty ($_server[' http_client_ip ')) {$cip = $_server[' http_client_ip '];  } ElseIf (!empty ($_server[' http_x_forwarded_for ')) {$cip = $_server[' http_x_forwarded_for '];  } ElseIf (!empty ($_server[' remote_addr ')) {$cip = $_server[' remote_addr '];  } else{$cip = ';  }  return $CIP;} Get visitor Source Function Getreferer () {  if (isset ($_server[' http_referer ')) {return $_server[' http_referer '];  }  Return ';} ?>

2. Normal access Using Curl

<?phpfunction Docurl ($url, $data =array (), $header =array (), $timeout =30) {   $ch = Curl_init ();  curl_setopt ($ch, Curlopt_url, $url);  curl_setopt ($ch, Curlopt_httpheader, $header);  curl_setopt ($ch, Curlopt_post, true);  curl_setopt ($ch, Curlopt_postfields, Http_build_query ($data));  curl_setopt ($ch, Curlopt_returntransfer, true);  curl_setopt ($ch, Curlopt_timeout, $timeout);   $response = curl_exec ($ch);   if ($error =curl_error ($ch)) {die ($error);  }   Curl_close ($ch);   return $response; }//Call the ' http://www.uxuew.cn/server.php ', $response = Docurl ($url); Echo $response;? >

3. Use Curl to simulate IP and source access

Analog sources

curl_setopt ($ch, Curlopt_referer, ' source ');

Analog IP

curl_setopt ($ch, Curlopt_httpheader, Array (' CLIENT-IP: Analog ip ', ' x-forwarded-for: Analog IP '));

The complete code is as follows:

<?phpfunction Docurl ($url, $data =array (), $header =array (), $referer = ", $timeout =30) {   $ch = Curl_init ();  curl_setopt ($ch, Curlopt_url, $url);  curl_setopt ($ch, Curlopt_httpheader, $header);  curl_setopt ($ch, Curlopt_post, true);  curl_setopt ($ch, Curlopt_postfields, Http_build_query ($data));  curl_setopt ($ch, Curlopt_returntransfer, true);  curl_setopt ($ch, Curlopt_timeout, $timeout);   Analogue source  curl_setopt ($ch, Curlopt_referer, $referer);   $response = curl_exec ($ch);   if ($error =curl_error ($ch)) {die ($error);  }   Curl_close ($ch);   return $response; }//Call the ' http://www.example.com/server.php ', $data = Array (); Set Ip$header = Array (  ' client-ip:192.168.1.100 ',  ' x-forwarded-for:192.168.1.100 ');//Set Source $referer = ' Http://www.uxuew.cn/'; $response = Docurl ($url, $data, $header, $referer, 5); Echo $response;? >

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.