PHP Curl fake IP address and header information Code instance

Source: Internet
Author: User
Tags curl mongodb php code postgresql redis firewall


This article mainly introduces the PHP curl fake IP address and header information code example, this article gives the server and client implementation code, to provide forgery and server-side detection code, need friends can refer to the



Although Curl is powerful, but can only forge $_server["Http_x_forwarded_for"], for most IP address detection program, $_server["REMOTE_ADDR" is difficult to be forged:



First, it's client.php code.



The code is as follows:




$headers['CLIENT-IP'] = '202.103.229.40';

$headers['X-FORWARDED-FOR'] = '202.103.229.40';

$headerArr = array();

Foreach( $headers as $n => $v ) {

$headerArr[] = $n .':' . $v;

}

Ob_start();

$ch = curl_init();

Curl_setopt ($ch, CURLOPT_URL, "http://localhost/curl/server.php");

Curl_setopt ($ch, CURLOPT_HTTPHEADER , $headerArr ); //Structure IP

Curl_setopt ($ch, CURLOPT_REFERER, "http://www.163.com/ "); //Structure

Curl_setopt( $ch, CURLOPT_HEADER, 1);

Curl_exec($ch);

Curl_close ($ch);

$out = ob_get_contents();

Ob_clean();

Echo $out;



And then the server.php.



The code is as follows:





Function GetIP(){

If(!emptyempty($_SERVER["HTTP_CLIENT_IP"]))

$cip = $_SERVER["HTTP_CLIENT_IP"];

Else if(!emptyempty($_SERVER["HTTP_X_FORWARDED_FOR"]))

$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];

Else if(!emptyempty($_SERVER["REMOTE_ADDR"]))

$cip = $_SERVER["REMOTE_ADDR"];

Else

$cip = "Unable to get!";

Return $cip;

}
echo "
Access IP: ". GetIP (). "
"; echo "
Access routing: ". $_server[" Http_referer "];


Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

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.