Page 1 of 1

PHP code within XML – Hidden execution of code - please help

Posted: Tue Dec 01, 2009 5:24 am
by Php Freek
Hi all,

I am hosting an Ecommerce site and there are lots of users who use our XML files to get daily updates of the gadgets and devices.

All the URLs are like
http://www.example.com/test.xml

I want to keep track of this xml files. When any xml file is called on internet, I want to update the view count of the items displayed in this xml file.

In XML file, I can not put the PHP Code so I can not use it directly.

Is there any thing on sever setting which may allow us to exec code when certain URL request comes?

If so how can I do that any in which language I need to do coding?

Is there any other way like .htaccess or anything else to achieve this? Also, I do not want redirect the XML URL.

Any idea, help or suggestion will be great in this case since this will help me to keep track of each devices and how much popular it is?

Thanks in advance.

Maria

Re: PHP code within XML – Hidden execution of code - please help

Posted: Tue Dec 01, 2009 9:55 am
by AbraCadaver
If you use an .htaccess rewrite rule to rewrite all .xml to getxml.php?file=test you can then have getxml.php update the counter in the correct file and then display the xml (not tested):

.htaccess

Code: Select all

RewriteRule ^(.*)?.xml$ getxml.php?file=$1 [QSA,L]
getxml.php

Code: Select all

<?php
$xml_file = $_GET['file'];
// load /path/to/$xml_file . xml
// update counter
// save /path/to/$xml_file . xml
// display xml
?>
-Shawn