Making an AJAX call to another page via a proxy script logs me out

Hi there,

  • Within my Yii application, I have a web service returning JSON content.

  • For security reasons, the web service cannot be accessed directly by an AJAX request, but has to go through a server-side proxy which will provide a domain access key. The proxy I use is based on the one you’ll get by Googling Troy Wolf proxy (I can’t post links apparently)

  • Problem: When I call the web service, via the proxy ([mysiteurl]/proxy.php?proxy_url=[mysiteurl]/mywebservice/data.json), it returns the data successfully. But it also logs me out of my Yii site!

Any ideas as to why this happens and how to approach the problem would be really appreciated!

Any thoughts anyone?

As I see in the proxy script:


$ary_headers = split("\n", $h->header);

foreach($ary_headers as $hdr) { header($hdr); }

This sends all the headers recieved from the other site to your client. So you need to investigate them. Perhaps some kind of cookie deletion ( the session cookie ) is happening or so.

Thank you very much Georgi - the issue relating to cookies was spot on (seems obvious now ;o)

I have resolved the issue by changing to the proxy script at http://codefury.net/2010/06/ajax-proxy-a-php-ajax-proxy-with-cookie-support/

Thanks again!