title: How to make my PHP Socket Server send a policy file to flash clients?
body: <p>My flash game needs to connect to my PHP Socket Server. Because of security things, a policy file has to be send to the flash client when it tries to connect.</p>
  
  <p>The following is what I've done.</p>
  
  <p>In Actionscript / Flex 3 / Flash:</p>
  
  <pre><code>Security.loadPolicyFile("http://[SERVER.IP]:9000/crossdomain.xml");
  socket.connect(hostName, port); //connect to the socket
  [rest of original code]
  </code></pre>
  
  <p>To make the socket server respond on the request, I added the following to the server:</p>
  
  <pre><code>elseif (preg_match("/policy-file-request/i", $buffer) or preg_match("/crossdomain/i", $buffer)) {
                      socket_write($socket, '&lt;?xml version="1.0"?&gt;&lt;cross-domain-policy&gt;&lt;site-control permitted-cross-domain-policies="all"/&gt;&lt;allow-access-from domain="*" to-ports="9000" /&gt;&lt;/cross-domain-policy&gt;');
                      unset($read_sockets[array_search($socket, $read_sockets)]);
                      socket_shutdown($socket, 2);
                      socket_close($socket);
  </code></pre>
  
  <p>I however get the following error: "Ignoring policy file at (URL) due to missing Content-Type." So, I tried to fix this by adding a header right above my xml code:</p>
  
  <pre><code>socket_write($socket, "Content-Type: text/xml\n");
  </code></pre>
  
  <p>Unfortunately, I still get the same error. Am I giving the content type in a wrong way?</p>