You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-6Lines changed: 36 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,12 @@
1
1
# Simple PHP Proxy
2
2
3
-
This proxy script allows you to forward all HTTP/HTTPS requests to another server. Works for all common request types
4
-
including GET, POST requests with files, PATCH and PUT requests. It has minimal set of requirements
5
-
(PHP >=5.6, libcurl, gzip) which are available even on the smallest free hostings and has its own simple authorization
3
+
This proxy script allows you to forward all HTTP/HTTPS requests to another server. Works for all common request types
4
+
including GET, POST requests with files, PATCH and PUT requests. It has minimal set of requirements
5
+
(PHP >=5.6, libcurl, gzip) which are available even on the smallest free hostings and has its own simple authorization
6
6
and cookie support.
7
7
8
8
## How to use
9
+
9
10
* 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)
10
11
* Make a cURL request targeting this script
11
12
* Add **Proxy-Auth** header with auth key [found here](https://github.com/zounar/php-proxy/blob/master/Proxy.php#L40)
@@ -15,14 +16,16 @@ and cookie support.
15
16
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.
16
17
17
18
## How to use (via composer)
18
-
This might be useful when you want to redirect requests coming into your app.
19
+
20
+
This might be useful when you want to redirect requests coming into your app.
19
21
20
22
* Run `composer require zounar/php-proxy`
21
23
* Add `Proxy::run();` line to where you want to execute it (usually into a controller action)
22
24
* In this example, the script is in `AppController` - `actionProxy`:
25
+
23
26
```
24
27
use Zounar\PHPProxy\Proxy;
25
-
28
+
26
29
class AppController extends Controller {
27
30
28
31
public function actionProxy() {
@@ -34,6 +37,7 @@ This might be useful when you want to redirect requests coming into your app.
34
37
}
35
38
}
36
39
```
40
+
37
41
* Make a cURL request to your web
38
42
* In the example, it would be `http://your-web.com/app/proxy`
39
43
* Add **Proxy-Auth** header with auth key [found here](https://github.com/zounar/php-proxy/blob/master/Proxy.php#L40)
@@ -44,7 +48,8 @@ In order to protect using proxy by unauthorized users, consider changing `Proxy-
44
48
`Proxy::$AUTH_KEY = '<your-new-key>';` before `Proxy::run()`. Then change the token in all your requests.
45
49
46
50
## Usage example
47
-
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.
51
+
52
+
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.
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.
62
89
63
90
```php
@@ -73,6 +100,7 @@ curl_exec($request);
73
100
```
74
101
75
102
## Specifying User-Agent
103
+
76
104
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.
77
105
78
106
```php
@@ -88,6 +116,7 @@ curl_exec($request);
88
116
```
89
117
90
118
## Error 301 Moved permanently
119
+
91
120
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`.
92
121
93
122
```php
@@ -103,6 +132,7 @@ curl_exec($request);
103
132
```
104
133
105
134
## Save response into variable
135
+
106
136
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.
0 commit comments