Giter Site home page Giter Site logo

php-cross-domain-proxy's Introduction

PHP Cross Domain (AJAX) Proxy

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.

Installation

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

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:

$('#target').load(
	'http://www.yourdomain.com/proxy.php', {
		csurl: 'http://www.cross-domain.com/',
		param1: value1, 
		param2: value2
	}
);

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.

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:

$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
	if (options.url.match(/^https?:/)) {
		options.headers['X-Proxy-URL'] = options.url;
		options.url = '/proxy.php';
	}
});

Configuration

For security reasons don't forget to define all the valid requests into top section of proxy.php file:

$valid_requests = array(
	'http://www.domainA.com/',
	'http://www.domainB.com/path-to-services/service-a'
);

php-cross-domain-proxy's People

Contributors

audionerd avatar softius avatar szeist avatar wojons avatar

Watchers

 avatar  avatar

Forkers

germankingyt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.