IPIPGO ip proxy PHP Web Proxy Demo: Simple Proxy Tutorial

PHP Web Proxy Demo: Simple Proxy Tutorial

Teach you to use PHP to get a web proxy Recently, a friend always asked me how to get a web proxy, said that they want to get a convenient to use. It is just that today we take ipipgo's proxy IP to give a chestnut, teach you to use PHP the whole simple version. First of all, to make it clear ah, this thing is not for you to do bad things, the main ...

PHP Web Proxy Demo: Simple Proxy Tutorial

Hands-on with PHP to get a web proxy

Recently, a friend always ask me how to whole web proxy, said they want to get a convenient to use. It is just that today we take ipipgo proxy IP to give a chestnut, teach you to use PHP the whole simple version. First, let me make it clear, this thing is not for you to do bad things, mainly used to test the effect of multi-region access to the site, or do data collection and other serious things.

Don't be lazy with your preparation.

First you have to have three things on hand:
1. A server that can run PHP (web hosting is fine)
2. ipipgo's proxy package (pay-as-you-go is fine for newbies)
3. Notepad or code editor

Focused Reminder:Remember to set the whitelist to your own server IP in the ipipgo background, otherwise don't blame me for not mentioning that the proxy can't connect later.

The core code is just these lines


<?php
// 代理服务器配置
$proxy_ip = 'ipipgo分配给你的代理地址';
$proxy_port = 端口号;

$target_url = $_GET['url'];  // 要访问的网站

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip.':'.$proxy_port);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// 这两行很重要,不加容易超时
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);

$output = curl_exec($ch);
curl_close($ch);

echo $output;
?>

It's more reliable to add some useful features

Can't get enough of the basic version? Let's go up a level:

1. Request header camouflage:


curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'User-Agent: Mozilla/5.0 (Windows NT 10.0)'
]).

2. Error handling:


if(curl_errno($ch)){
    echo 'Error: '.curl_error($ch); exit;; if(curl_errno($ch){)
    exit;
}

Frequently Asked Questions QA

Q: What about slow agents?
A: ① check the geographic location of the server ② change ipipgo BGP line ③ adjust the timeout time

Q: How to change IP automatically?
A: Use ipipgo's dynamic package and call their API to change the IP before each request.

Q:Access to HTTPS website report error?
A: Add it in the curl configuration:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

Guide to avoiding the pit

Newbies are most likely to plant in these places:
1. Forgetting to turn on the server's curl extension
2. Proxy IP format is written as http://开头 (just fill in the IP directly)
3. Failure to whitelist results in connection failure
4. Frequent requests are blocked by the target site IP (this time it is necessary to use ipipgo's rotating IP function)

Finally, to be honest, it's quite troublesome to build and maintain your own proxies. If you use it for a long time, you might as well use ipipgo's ready-made API interface, their agent pool is large, and there are technicians to help troubleshoot problems. Especially for those who are doing projects, the time saved can be used for two more jobs.

This article was originally published or organized by ipipgo.https://www.ipipgo.com/en-us/ipdaili/33912.html

business scenario

Discover more professional services solutions

💡 Click on the button for more details on specialized services

New 10W+ U.S. Dynamic IPs Year-End Sale

Professional foreign proxy ip service provider-IPIPGO

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact Us

13260757327

Online Inquiry. QQ chat

E-mail: hai.liu@xiaoxitech.com

Working hours: Monday to Friday, 9:30-18:30, holidays off
Follow WeChat
Follow us on WeChat

Follow us on WeChat

Back to top
en_USEnglish