title: php proxy for flash twitter api call (with dynamic get array)
body: <p>I came up with this twitter project in flash, and once i was done and tried to put it online i ran into a sandbox error. From what i've read it looks like i just need to setup a php proxy file. Which I get and understand. All the tutorials i've been able to find were for simple urls with no GET data being passed in the URL. For my project the GET data is dynamic so i can't just put a set url in the php proxy and i dont understand php well enough to figure out how to get the get data into the proxy url..
  so here's what i know how to edit in Flex:
  <img src="https://i.stack.imgur.com/QnjB3.png" alt="enter image description here"></p>
  
  <p>heres a full example api call i would need to make:</p>
  
  <pre><code>http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=brybam&amp;?page=1
  </code></pre>
  
  <p>and here is a php proxy script that was reccomended online:</p>
  
  <pre><code>&lt;?php
  
  $post_data = $HTTP_RAW_POST_DATA;
  
  $header[] = "Content-type: text/xml";
  $header[] = "Content-length: ".strlen($post_data);
  
  $ch = curl_init( $_GET['url'] ); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  
  if ( strlen($post_data)&gt;0 ){
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  }
  
  $response = curl_exec($ch);     
  $response_headers = curl_getinfo($ch);     
  
  if (curl_errno($ch)) {
      print curl_error($ch);
  } else {
      curl_close($ch);
      header( 'Content-type: ' . $response_headers['content-type']);
      print $response;
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>Alright so getting started I just need to make the php script into a file something like twitter.php and just put it on my domain. Then I'm assuming in the URL box for the http service setup in Flex put and reenter it as something like this:</p>
  
  <pre><code>http://mydomain.com/twitter.php?screen_name=brybam&amp;?page=1
  </code></pre>
  
  <p>SO what im asking is because my understanding of php is very limited, how exactly would I take the above script and make it capable of being passed </p>
  
  <pre><code>http://mydomain.com/twitter.php?screen_name=brybam&amp;?page=1
  </code></pre>
  
  <p>with Flex and be able to take different potential arguments?</p>
  
  <p>I think it may be something like </p>
  
  <pre><code>$page = $_GET['page'];
  $screen_name = $_GET['screen_name'];
  </code></pre>
  
  <p>in the php file, but im not sure where i should be placing the variables into to make them part of the URL</p>
  
  <p>im sure this is cake if you know php and it would be awesome if someone could help me out with this, thanks!</p>
  
  <p>EDIT:
  I tried this, but got an error (the error is posted under what i tried)</p>
  
  <pre><code>&lt;?php
  $page = $_GET['page'];
  $screen_name = $_GET['screen_name'];
  $url = $_GET['url'];
  $post_data = $HTTP_RAW_POST_DATA;
  
  $header[] = "Content-type: text/xml";
  $header[] = "Content-length: ".strlen($post_data);
  
  $ch = curl_init("'url'?screen_name='$screen_name'&amp;?page='$page'"); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  
  if ( strlen($post_data)&gt;0 ){
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  }
  
  $response = curl_exec($ch);     
  $response_headers = curl_getinfo($ch);     
  
  if (curl_errno($ch)) {
      print curl_error($ch);
  } else {
      curl_close($ch);
      header( 'Content-type: ' . $response_headers['content-type']);
      print $response;
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>error msg:</p>
  
  <pre><code>The response is not a valid XML or a JSON string.
  
  Error on line 1 of document : The element type "meta" must be terminated by the matching end-tag "". Nested exception: The element type "meta" must be terminated by the matching end-tag "".
  </code></pre>