ajax-proxy.php; easily send cross-domain ajax requests via PHP
If you’ve developed an ajax site, at some point you may have ran into the problem of not being able to make ajax requests across different domains or sub-domains. And if you haven’t run into this problem yet – don’t worry, it’s coming.
Fortunately, my buddy Kenny whom I work with at HUGE wrote a quick PHP class to solve this problem. Basically, rather than routing requests directly to the other domain, you route them to a PHP file hosted on your local domain with the ajax-proxy class instantiated. The class then visits the URL on a separate domain and saves the response text via PHP, which has no cross domain limits. This response is then returned by the PHP class, and finally to your Ajax function!
There are a few other attempts at proxies out there, but as far as I know Kenny’s ajax-proxy is the only one that also sends cookies along with the request. So if the domain you are requesting to requires a cookie which is set on your original domain – no worries. Ajax-proxy takes care of it for you!
Don’t take my word for it. Read Kenny’s blog post for better details. Or just check it out at HUGE’s github account!
Leave a comment