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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Php Freek
Forum Newbie
Posts: 10
Joined: Sat Nov 03, 2007 12:06 am

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

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post 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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply