PHPackages                             zounar/php-proxy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. zounar/php-proxy

ActiveLibrary[HTTP &amp; Networking](/categories/http)

zounar/php-proxy
================

Forward your HTTP/HTTPS requests to another server.

1.1.0(5y ago)1814.0k↓22.2%95[3 PRs](https://github.com/zounar/php-proxy/pulls)unlicensePHPPHP &gt;=5.6.0

Since Dec 7Pushed 3y ago7 watchersCompare

[ Source](https://github.com/zounar/php-proxy)[ Packagist](https://packagist.org/packages/zounar/php-proxy)[ Docs](https://github.com/zounar/php-proxy)[ RSS](/packages/zounar-php-proxy/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Simple PHP Proxy
================

[](#simple-php-proxy)

This proxy script allows you to forward all HTTP/HTTPS requests to another server. Works for all common request types including GET, POST requests with files, PATCH and PUT requests. It has minimal set of requirements (PHP &gt;=5.6, libcurl, gzip) which are available even on the smallest free hostings and has its own simple authorization and cookie support.

How to use
----------

[](#how-to-use)

- Copy the [Proxy.php](Proxy.php) script to publicly-accessible folder of a PHP web server (the script is standalone and has no PHP dependencies)
- Make a cURL request targeting this script
- Add **Proxy-Auth** header with auth key [found here](https://github.com/zounar/php-proxy/blob/master/Proxy.php#L40)
- Add **Proxy-Target-URL** header with URL to be requested by the proxy
- (Optional) Add **Proxy-Debug** header for debug mode

In order to protect using proxy by unauthorized users, consider changing `Proxy-Auth` token in [proxy source file](https://github.com/zounar/php-proxy/blob/master/Proxy.php#L40) and in all your requests.

How to use (via composer)
-------------------------

[](#how-to-use-via-composer)

This might be useful when you want to redirect requests coming into your app.

- Run `composer require zounar/php-proxy`
- Add `Proxy::run();` line to where you want to execute it (usually into a controller action)
    - In this example, the script is in `AppController` - `actionProxy`: ```
        use Zounar\PHPProxy\Proxy;

        class AppController extends Controller {

            public function actionProxy() {
                Proxy::$AUTH_KEY = '';
                // Do your custom logic before running proxy
                $responseCode = Proxy::run();
                // Do your custom logic after running proxy
                // You can utilize HTTP response code returned from the run() method
            }
        }

        ```
- Make a cURL request to your web
    - In the example, it would be `http://your-web.com/app/proxy`
- Add **Proxy-Auth** header with auth key [found here](https://github.com/zounar/php-proxy/blob/master/Proxy.php#L40)
- Add **Proxy-Target-URL** header with URL to be requested by the proxy
- (Optional) Add **Proxy-Debug** header for debug mode

In order to protect using proxy by unauthorized users, consider changing `Proxy-Auth` token by calling `Proxy::$AUTH_KEY = '';` before `Proxy::run()`. Then change the token in all your requests.

Usage example
-------------

[](#usage-example)

Following example shows how to execute GET request to . Proxy script is at . All proxy settings are kept default, the response is automatically echoed.

```
$request = curl_init('http://www.foo.bar/Proxy.php');

curl_setopt($request, CURLOPT_HTTPHEADER, array(
    'Proxy-Auth: Bj5pnZEX6DkcG6Nz6AjDUT1bvcGRVhRaXDuKDX9CjsEs2',
    'Proxy-Target-URL: https://www.github.com'
));

curl_exec($request);
```

Debugging
---------

[](#debugging)

In order to show some debug info from the proxy, add `Proxy-Debug: 1` header into the request. This will show debug info in plain-text containing request headers, response headers and response body.

```
$request = curl_init('http://www.foo.bar/Proxy.php');

curl_setopt($request, CURLOPT_HTTPHEADER, array(
    'Proxy-Auth: Bj5pnZEX6DkcG6Nz6AjDUT1bvcGRVhRaXDuKDX9CjsEs2',
    'Proxy-Target-URL: https://www.github.com',
    'Proxy-Debug: 1'
));

curl_exec($request);
```

Specifying User-Agent
---------------------

[](#specifying-user-agent)

Some sites may return different content for different user agents. In such case add `User-Agent` header to cURL request, it will be automatically passed to the request for target site. In this case it's Firefox 70 for Ubuntu.

```
$request = curl_init('http://www.foo.bar/Proxy.php');

curl_setopt($request, CURLOPT_HTTPHEADER, array(
    'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0',
    'Proxy-Auth: Bj5pnZEX6DkcG6Nz6AjDUT1bvcGRVhRaXDuKDX9CjsEs2',
    'Proxy-Target-URL: https://www.github.com'
));

curl_exec($request);
```

Error 301 Moved permanently
---------------------------

[](#error-301-moved-permanently)

It might occur that there's a redirection when calling the proxy (not the target site), eg. during `http -> https` redirection. You can either modify/fix the proxy URL (which is recommended), or add `CURLOPT_FOLLOWLOCATION` option before `curl_exec`.

```
$request = curl_init('http://www.foo.bar/Proxy.php');

curl_setopt($request, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($request, CURLOPT_HTTPHEADER, array(
    'Proxy-Auth: Bj5pnZEX6DkcG6Nz6AjDUT1bvcGRVhRaXDuKDX9CjsEs2',
    'Proxy-Target-URL: https://www.github.com'
));

curl_exec($request);
```

Save response into variable
---------------------------

[](#save-response-into-variable)

The default cURL behavior is to echo the response of `curl_exec`. In order to save response into variable, all you have to do is to add `CURLOPT_RETURNTRANSFER` cURL option.

```
$request = curl_init('http://www.foo.bar/Proxy.php');

curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array(
    'Proxy-Auth: Bj5pnZEX6DkcG6Nz6AjDUT1bvcGRVhRaXDuKDX9CjsEs2',
    'Proxy-Target-URL: https://www.github.com'
));

$response = curl_exec($request);
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~111 days

Total

2

Last Release

1877d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f97e014d719a0ec692fd15760c1fc4b43bf83b4accf95a0ee164b2cb4c98e5f1?d=identicon)[robin.zounar@gmail.com](/maintainers/robin.zounar@gmail.com)

---

Top Contributors

[![zounar](https://avatars.githubusercontent.com/u/10967308?v=4)](https://github.com/zounar "zounar (8 commits)")[![ajaxray](https://avatars.githubusercontent.com/u/439612?v=4)](https://github.com/ajaxray "ajaxray (2 commits)")

---

Tags

curlcurlphphttphttp-proxyphpphp-proxyproxyproxy-scripthttpphpproxycurlhttp-proxyphp proxyproxy scriptcurlphp

### Embed Badge

![Health badge](/badges/zounar-php-proxy/health.svg)

```
[![Health](https://phpackages.com/badges/zounar-php-proxy/health.svg)](https://phpackages.com/packages/zounar-php-proxy)
```

###  Alternatives

[php-curl-class/php-curl-class

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs.

3.3k9.5M353](/packages/php-curl-class-php-curl-class)[smi2/phpclickhouse

PHP ClickHouse Client

83510.1M71](/packages/smi2-phpclickhouse)[popphp/pop-http

Pop Http Component for Pop PHP Framework

1018.5k13](/packages/popphp-pop-http)[gouguoyin/easyhttp

EasyHttp 是一个轻量级、语义化、对IDE友好的HTTP客户端，支持常见的HTTP请求、异步请求和并发请求，让你可以快速地使用 HTTP 请求与其他 Web 应用进行通信。

351.1k](/packages/gouguoyin-easyhttp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
