Download the PHP package zounar/php-proxy without Composer
On this page you can find all versions of the php package zounar/php-proxy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zounar/php-proxy
More information about zounar/php-proxy
Files in zounar/php-proxy
Package php-proxy
Short Description Forward your HTTP/HTTPS requests to another server.
License unlicense
Homepage https://github.com/zounar/php-proxy
Informations about the package 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 >=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
- Copy the 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
- 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 and in all your requests.
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
:
- In this example, the script is in
- Make a cURL request to your web
- In the example, it would be
http://your-web.com/app/proxy
- In the example, it would be
- Add Proxy-Auth header with auth key found here
- 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 = '<your-new-key>';
before Proxy::run()
. Then change the token in all your requests.
Usage example
Following example shows how to execute GET request to https://www.github.com. Proxy script is at http://www.foo.bar/Proxy.php. All proxy settings are kept default, the response is automatically echoed.
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.
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.
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
.
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.
All versions of php-proxy with dependencies
ext-curl Version *
ext-zlib Version *