<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Md Emran Hasan (phpfour) - Latest Comments in Cross-Domain AJAX calls using PHP</title><link>http://phpfour.disqus.com/</link><description>This is Emran Hasan's blog for PHP, CSS, XHTML, JavaScript, Web 2.0, AJAX, Usability, and Web Standards related views, ideas, and sharing.</description><language>en</language><lastBuildDate>Wed, 11 Mar 2009 03:44:33 -0000</lastBuildDate><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-7095314</link><description>My target page has '?page=x' to get the different contents according to x.&lt;br&gt;In this case, this script ignores '?page=x' and it results in getting the default contents.&lt;br&gt;&lt;br&gt;Could you please give me some hints how to fix this problem.&lt;br&gt;&lt;br&gt;Thank you!</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Piro</dc:creator><pubDate>Wed, 11 Mar 2009 03:44:33 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-5805484</link><description>Hi, thanx a lot for the code!!&lt;br&gt;&lt;br&gt;I've made the following solution with Jquery + PHP:&lt;br&gt;&lt;br&gt;$.get("http://mydomain.com/transport.php?action=&amp;lt;? echo urlencode('http://www.anotherdomain.com'); ?&amp;gt;&amp;method=get&amp;var1=variable1&amp;var2=variable2&amp;var3=variable3", &lt;br&gt;	function(serverResponse) { &lt;br&gt;		alert(serverResponse);&lt;br&gt;	}&lt;br&gt;);&lt;br&gt;&lt;br&gt;And I had to change the transport.php on the line 18 to: $action = $_REQUEST['action'];&lt;br&gt;&lt;br&gt;It worked very well!!&lt;br&gt;&lt;br&gt;Thx again</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Daniel</dc:creator><pubDate>Tue, 03 Feb 2009 07:27:43 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-4091693</link><description>I am using the following code, I get an error saying Object Not Found, can you please help ?&lt;br&gt;&lt;br&gt;&amp;lt;html&amp;gt;&lt;br&gt;&amp;lt;body&amp;gt;&lt;br&gt;&lt;br&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br&gt;&lt;br&gt;function ajaxFunction()&lt;br&gt;&lt;br&gt;{&lt;br&gt;&lt;br&gt;xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    &lt;br&gt;  xmlHttp.onreadystatechange=function()&lt;br&gt;    {&lt;br&gt;    if(xmlHttp.readyState==4)&lt;br&gt;      {&lt;br&gt;      document.myForm.time.value=xmlHttp.responseText;&lt;br&gt;      }&lt;br&gt;    }&lt;br&gt;xmlHttp.open("GET","transport.php?action="+urlencode("http://www.netshelter.net/time.php"),true);&lt;br&gt;  xmlHttp.send(null);   &lt;br&gt;  &lt;br&gt;   }&lt;br&gt;  &lt;br&gt;&amp;lt;/script&amp;gt;&lt;br&gt;  &lt;br&gt;&amp;lt;form name="myForm"&amp;gt;&lt;br&gt;Name: &amp;lt;input type="text" onkeyup="ajaxFunction();" name="username" /&amp;gt;&lt;br&gt;Time: &amp;lt;input type="text" name="time" /&amp;gt;&lt;br&gt;&amp;lt;/form&amp;gt;&lt;br&gt;&lt;br&gt;&amp;lt;/body&amp;gt;&lt;br&gt;&amp;lt;/html&amp;gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Nick Syed</dc:creator><pubDate>Mon, 01 Dec 2008 16:04:28 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-3910306</link><description>Nice to know that.&lt;br&gt;Thank you</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">rollstag</dc:creator><pubDate>Thu, 20 Nov 2008 04:39:23 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-2839015</link><description>Hi, i've tried using your script and on my homeserver it runs fine but on my shared hoster it hangs at curl_exec().&lt;br&gt;Is there anything you know of that causes this freezing/hanging?</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Rene Veerman</dc:creator><pubDate>Thu, 25 Sep 2008 05:36:17 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-2839010</link><description>I have tried this proxy approach, but neither Firefox nor IE 6 will allow me to call a php page with XMLHttpRequest. Of course, it won't allow me to call webservice cross-domain either.&lt;br&gt;Thanks.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Kelvin</dc:creator><pubDate>Mon, 05 May 2008 18:11:44 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-2839001</link><description>there's a typo:&lt;br&gt;&lt;br&gt;you wrote this:&lt;br&gt;if ($key != 'url' || $key != 'method')&lt;br&gt;&lt;br&gt;while you obviously meant this:&lt;br&gt;if ($key != 'url' &amp;amp;&amp;amp; $key != 'method')&lt;br&gt;&lt;br&gt;&lt;br&gt;(since ($key != 'url' || $key != 'method') is always true)</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">François Labarde</dc:creator><pubDate>Mon, 07 Apr 2008 11:34:39 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-2839000</link><description>On the transport file you can't get the action because is named url&lt;br&gt;&lt;br&gt;You must change that line :&lt;br&gt;&lt;br&gt;$action = $_REQUEST['url'];&lt;br&gt;&lt;br&gt;To :&lt;br&gt;&lt;br&gt;$action = $_REQUEST['action'];&lt;br&gt;&lt;br&gt;Or change this :&lt;br&gt;&lt;br&gt;xmlHttp.open(“GET”, ‘http://myserver.com/transport.php?action=’ +   10:                     urlencode(‘different-server.com/return_call.php’) +  11:                     ‘&amp;amp;method=get&amp;amp;data1=101&amp;amp;data2=pass’, true );&lt;br&gt;&lt;br&gt;With this :&lt;br&gt;&lt;br&gt;xmlHttp.open(“GET”, ‘http://myserver.com/transport.php?url=’ +   10:                     urlencode(‘different-server.com/return_call.php’) +  11:                     ‘&amp;amp;method=get&amp;amp;data1=101&amp;amp;data2=pass’, true );</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">SuNcO</dc:creator><pubDate>Wed, 26 Mar 2008 12:47:28 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-2839006</link><description>@Loic Hoguin: Yes, you're right. Also, to be safe, using a http wraper class supporting both cURL and fsockopen (like mine &lt;a href="http://www.phpfour.com/blog/2008/01/20/php-http-class/" rel="nofollow"&gt;one&lt;/a&gt;) can be suggested to avoid problem.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">phpfour</dc:creator><pubDate>Thu, 06 Mar 2008 13:20:51 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-2839002</link><description>Indeed, filtering using REMOTE_ADDR is the best if both servers are yours.&lt;br&gt;&lt;br&gt;What's important to note, too, is that if curl_exec can't fetch the data for some reasons it will return false. That means that your script will echo nothing. People using it should take care on the javascript side to check the data they get and if it's empty display an error.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Loïc Hoguin</dc:creator><pubDate>Thu, 06 Mar 2008 12:22:48 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-2839003</link><description>@Loic Hoguin: I completely agree with you that this script shouldn't allow other person from web to misuse it for their own use.&lt;br&gt;&lt;br&gt;But I would suggest using $_SERVER['REMOTE_ADDR'] to block request from scripts other than the server I'm invoking it from. &lt;br&gt;&lt;br&gt;The reason I think that way is, in the project I used it, the other server was also mine and I needed to communicate between them. As the output was quite dynamic, caching couldn't be done. &lt;br&gt;&lt;br&gt;But then again, if needed, caching can be added easily. I will be uploading one with caching later tonight.&lt;br&gt;&lt;br&gt;Thanks everybody for commenting !</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">phpfour</dc:creator><pubDate>Thu, 06 Mar 2008 07:12:30 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-2839007</link><description>I think that Loic Hoguin's recommendation is accurate. &lt;br&gt;No comment ?</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">zack</dc:creator><pubDate>Thu, 06 Mar 2008 06:22:05 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-2839009</link><description>This is a nice tutorial with explanation. Well I want t o show if you want to use jquery (&lt;a href="http://jquery.com/" rel="nofollow"&gt;http://jquery.com/&lt;/a&gt;).&lt;br&gt;&lt;br&gt;If you want to get json data , then you can easily use &lt;a href="http://docs.jquery.com/Ajax/jQuery.getJSON" rel="nofollow"&gt;getJSON&lt;/a&gt;. &lt;br&gt;&lt;br&gt;&lt;code&gt;$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&amp;amp;tagmode=any&amp;amp;format=json&amp;amp;jsoncallback=?",&lt;br&gt;     function(data){&lt;br&gt;          $.each(data.items, function(i,item){&lt;br&gt;               $("").attr("src", item.media.m).appendTo("#images");&lt;br&gt;     });&lt;br&gt;});&lt;/code&gt;&lt;br&gt;&lt;br&gt;Or if you don’t want to get other type of data like XML or other type, then you have to use cURL in PHP:&lt;br&gt;&lt;br&gt;&lt;code&gt;$.ajax({&lt;br&gt;     type:   "GET",&lt;br&gt;     url :     ”http://myserver.com/transport.php?action=’ + &lt;br&gt;               urlencode(‘different-server.com/return_call.php’) +&lt;br&gt;               ‘&amp;amp;method=get&amp;amp;data1=101&amp;amp;data2=pass”,&lt;br&gt;     success: function(serverResponse)&lt;br&gt;          /*parse serverResponse data    */ &lt;br&gt;});&lt;/code&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Saidur Rahman</dc:creator><pubDate>Thu, 06 Mar 2008 02:05:27 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-2839008</link><description>@H2: Of course. Thanks !</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">phpfour</dc:creator><pubDate>Thu, 06 Mar 2008 02:05:04 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-2839005</link><description>Does it also support POST simulation?&lt;br&gt;&lt;br&gt;Good Work Batman!</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">H2</dc:creator><pubDate>Thu, 06 Mar 2008 01:59:27 -0000</pubDate></item><item><title>Re: Cross-Domain AJAX calls using PHP</title><link>http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/#comment-2839004</link><description>Please please please add some caching mechanism to your script. You do not want to allow some kiddie to flood another website using your script. Even 1-minute cache is enough, but just don't call this website everytime like this. Not only will it be slow but the other site owner might get angry at you.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Loïc Hoguin</dc:creator><pubDate>Wed, 05 Mar 2008 17:26:10 -0000</pubDate></item></channel></rss>