Skip to content

Commit e1e6d86

Browse files
committed
Revised documentation
1 parent b49ab33 commit e1e6d86

File tree

1 file changed

+74
-23
lines changed

1 file changed

+74
-23
lines changed

README.md

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,69 @@
1-
PHP Cross Domain (AJAX) Proxy
2-
==============
1+
# PHP CORS Proxy
32

4-
An application proxy that can be used to transparently transfer all kind of requests ( including of course XMLHTTPRequest ) to any third part domain. It is possible to define a list of acceptable third party domains and you are encouraged to do so. Otherwise the proxy is open to any kind of requests.
3+
*Formerly known as "PHP Cross Domain (AJAX) Proxy"*
54

6-
If it is possible to enable CORS on your application server, this proxy is not necessary. Have a look at [how you can enable CORS on your server](http://enable-cors.org/server.html) for further information.
5+
A CORS proxy that allows cross domain requests. It can be used to access resources from third part websites when it's not possible to enable CORS.
76

8-
PHP 5.3+
7+
**Note**: Please check whether this solution is indeed necessary by having a look at [how you can enable CORS on your server](http://enable-cors.org/server.html).
98

10-
Installation
11-
--------------
9+
## Overview
1210

13-
The proxy is indentionally limited to a single file. All you have to do is to place `proxy.php` under your application
1411

15-
Whenever you want to make a cross domain request, just make a request to http://www.yourdomain.com/proxy.php and specify the cross domain URL by using `csurl` parameter. Obviously, you can add more parameters according to your needs; note that the rest of the parameters will be used in the cross domain request. For instance, if you are using jQuery:
12+
### Features
13+
14+
* Acts as a reverse proxy: request headers and data are propagated from proxy to server. Similarly, response headers and data are propagated from proxy to client.
15+
* Provides support for all methods GET, POST, PUT, DELETE.
16+
* Requests can be filtered against a list of trusted domains / URLs.
17+
* External configuration (Work in progress)
18+
* Error handling i.e. when server is not available (Work in progress)
19+
* Debugging mode (Work in progress)
20+
21+
### Requirements
22+
23+
PHP Cors Proxy works with PHP 5.3+ or above.
24+
25+
### Author
26+
27+
Iacovos Constantinou - [email protected]
28+
See also the list of [contributors](https://github.com/softius/php-cross-domain-proxy/graphs/contributors) which participated in this project.
29+
30+
31+
### License
32+
33+
PHP CORS Proxy is licensed under GPL-3.0. See `LICENCE.txt` file for further details.
34+
35+
36+
## Installation
37+
38+
**Using composer**
39+
40+
```
41+
composer require softius/cors-proxy
42+
```
43+
44+
**Manual installation**
45+
46+
The proxy is indentionally limited to a single file. All you have to do is to place `proxy.php` under the public folder of your application.
47+
48+
### Configuration
49+
50+
For security reasons don't forget to define all the trusted domains / URLs into top section of `proxy.php` file:
1651

1752
``` JAVASCRIPT
18-
$('#target').load(
19-
'http://www.yourdomain.com/proxy.php', {
20-
csurl: 'http://www.cross-domain.com/',
21-
param1: value1,
22-
param2: value2
23-
}
53+
$valid_requests = array(
54+
'http://www.domainA.com/',
55+
'http://www.domainB.com/path-to-services/service-a'
2456
);
2557
```
2658

27-
It’s worth mentioning that all request methods are working GET, PUT, POST, DELETE are working and headers are taken into consideration. That is to say, headers sent from browser to proxy are used in the cross domain request and vice versa.
59+
**Note**: There is currently ongoing work to allow configuration outside the `proxy.php`
60+
61+
## Usage
62+
It is possible to initiate a cross domain request either by providing the `X-Proxy-URL` header or by passing a special `GET` parameter. The former method is strongly suggested since it doesn't modify the request query. Also, the request looks more clear and easier to understand.
63+
64+
### Using headers
2865

29-
You can also specify the URL with the `X-Proxy-URL` header, which might be easier to set with your JavaScript library. For example, if you wanted to automatically use the proxy for external URL targets, for GET and POST requests:
66+
It is possible to specify the target URL with the `X-Proxy-URL` header, which might be easier to set with your JavaScript library. For example, if you wanted to automatically use the proxy for external URL targets, for GET and POST requests:
3067

3168
``` JAVASCRIPT
3269
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
@@ -37,16 +74,30 @@ $.ajaxPrefilter(function(options, originalOptions, jqXHR) {
3774
});
3875
```
3976

40-
Configuration
41-
--------------
77+
The following example uses `curl`
78+
79+
```
80+
curl -v -H "X-Proxy-URL: http://cross-domain.com" http://mydomain.com/proxy.php
81+
```
4282

43-
For security reasons don't forget to define all the valid requests into top section of `proxy.php` file:
83+
84+
### Using query
85+
86+
In order to make a cross domain request, just make a request to http://www.yourdomain.com/proxy.php and specify the target URL by using the `csurl` (GET) parameter. Obviously, you can add more parameters according to your needs; note that the rest of the parameters will be used in the cross domain request. For instance, if you are using jQuery:
4487

4588
``` JAVASCRIPT
46-
$valid_requests = array(
47-
'http://www.domainA.com/',
48-
'http://www.domainB.com/path-to-services/service-a'
89+
$('#target').load(
90+
'http://www.yourdomain.com/proxy.php', {
91+
csurl: 'http://www.cross-domain.com/',
92+
param1: value1,
93+
param2: value2
94+
}
4995
);
5096
```
5197

98+
The following example uses `curl`
99+
100+
```
101+
curl -v http://mydomain.com/proxy.php?csurl=http://www.cross-domain.com/&param1=value1&param2=value2
102+
```
52103

0 commit comments

Comments
 (0)