Tuesday, May 24, 2011

Transparent PHP proxy with GET, POST and HEADER support.

I needed to do cross-domain AJAX calls from a jQuery front-end to a PHP backend which was on another domain, and couldn't find a complete, functional example online... so I created my own. Since both servers had PHP (but the backend needed extra stuff that wasn't on the frontend server), doing a PHP Proxy was a great idea.


What this proxy supports:
  • GET and POST requests (POST was the whole reason for this, since jsonp doesn't support it!)
  • HTTP_REFERER check (only accept requests from one server)
  • COOKIES, in both directions (setting from the backend and sending from the frontend)
  • HEADERS, all of them, in both directions. This means it's a transparent proxy (yay!)
What it doesn't support (yet, maybe):
  • Dynamic destination (though that's relatively trivial to change), because I don't need it.
  • Load Balancing/Cycling, I may add this as a personal exercise in the future.
  • Authentication, beyond the referer check, or session (this should be handled by the backend anyway)
The Code

Because blogger.com sucks with code, the code is available directly on Google Code, at the following URL:
http://code.google.com/p/php-transparent-proxy/

No comments:

Post a Comment