0

I have these lines of code in my .htaccess.

My problem is is this line of code is in my .htaccess i want to put it in my php.

I want to do is convert it to php header does anyone know how to do it?

AddType application/xml .xml .rss
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"

1 Answers1

2

Did you even try to implement that yourself or read at http://php.net/manual/en/function.header.php?

Write those lines before the first output of the file.
Should do the job (although untested):

<?php
// ...
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: origin, x-requested-with, content-type');
header('Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS');
?>
thedom
  • 2,498
  • 20
  • 26
  • how about the AddType application/xml .xml .rss? – user3925277 Aug 11 '14 at 13:29
  • That's an Apache directive telling that file ``xml`` and ``rss`` extensions are delivered with the mimetype ``application/xml``. Afaik it's not possible to directly map that within the header but implement code which checks what to send as mimetype. The code for setting the mimetype would then be ``header('Content-type: application/xml');`` – thedom Aug 11 '14 at 13:38