FMR Posted March 6, 2016 Share Posted March 6, 2016 Hello everyone, I'm trying to include this PHP code inside of a .xml: <?php$parent = basename(dirname($_SERVER['PHP_SELF']));echo $parent;?> The code doesn't seem to be recognized at all. I tried to create a .htaccess file and dropped it in the same folder as the .xml: AddHandler x-httpd-php .xmlAddHandler php-script .php .xmlAddHandler php5-script .php .xmlAddType application/x-httpd-php .xmlAddType application/x-httpd-php .xml I was trying the parse .xml as .php. I changed the header of the xml for: <?phpheader("Content-Type: text/xml;charset=utf-8");?> and still no luck. I attached the xml file with this post. I must say. I'm out of ideas for something I am sure is possible. If someone has any ideas at all it would be really appreciated. Thank you in advance! FMR products.xml Link to comment Share on other sites More sharing options...
Ingolme Posted March 6, 2016 Share Posted March 6, 2016 You could just leave the extension as .php. As long as the content-type header is set to text/xml it should still be interpretted as XML by the browser. If you really need the extension to be .xml, the AddType directive should probably work, what happened when you tried it? Link to comment Share on other sites More sharing options...
FMR Posted March 6, 2016 Author Share Posted March 6, 2016 You could just leave the extension as .php. As long as the content-type header is set to text/xml it should still be interpretted as XML by the browser. If you really need the extension to be .xml, the AddType directive should probably work, what happened when you tried it? The file just won't load. I tried to change the extension but it didn't work either. Link to comment Share on other sites More sharing options...
FMR Posted March 6, 2016 Author Share Posted March 6, 2016 You could just leave the extension as .php. As long as the content-type header is set to text/xml it should still be interpretted as XML by the browser. If you really need the extension to be .xml, the AddType directive should probably work, what happened when you tried it? In fact, I don't know if this is related but when I try to load the file 1 on itself I get this error: Warning: Cannot modify header information - headers already sent by (output started at /home/steph941/public_html/miseau-point/code/etudiantfr/data-provider/products.php:1) in /home/steph941/public_html/miseau-point/code/etudiantfr/data-provider/products.php on line 2 I checked for white spaces and there is none. Link to comment Share on other sites More sharing options...
Ingolme Posted March 6, 2016 Share Posted March 6, 2016 The file is saved as UTF-8 with a Byte-Order Mark. There are actually three invisible characters being sent before the header. You should open the file in a text editor and change the encoding to be UTF-8 without BOM. Link to comment Share on other sites More sharing options...
FMR Posted March 6, 2016 Author Share Posted March 6, 2016 The file is saved as UTF-8 with a Byte-Order Mark. There are actually three invisible characters being sent before the header. You should open the file in a text editor and change the encoding to be UTF-8 without BOM. I remove the BOM and the error is gone. But it still doesn't work. I guess I must keep the .xml extension. But the server just doesn't recognize the php inside it. Any idea on how to force it? Thank you for the help! Link to comment Share on other sites More sharing options...
Ingolme Posted March 6, 2016 Share Posted March 6, 2016 You should not need the .xml extension. What happens when you open the file in your browser? Link to comment Share on other sites More sharing options...
FMR Posted March 6, 2016 Author Share Posted March 6, 2016 You should not need the .xml extension. What happens when you open the file in your browser? When I change the extension I also change all references to productsXMLFile : "data-provider/products.xml", for productsPHPFile : "data-provider/products.php", and url: configOptions.productsXMLFile+"?file="+DateTime.getTime(), dataType: "xml", for url: configOptions.productsPHPFile+"?file="+DateTime.getTime(), dataType: "php", inside of the .js But I get an error message saying: Can't load products. That's why I suspected I couldn't change the extension. There is something I'm missing. Link to comment Share on other sites More sharing options...
FMR Posted March 6, 2016 Author Share Posted March 6, 2016 You should not need the .xml extension. What happens when you open the file in your browser? When I open the file in php without BOM with direct path it works but when I try to open the page which needs the products.xml (or .php) I get the "can't load products" error. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now