/    Sign up×
Community /Pin to ProfileBookmark

PHP ignoring Server-Side Includes?

I’m using an XML-based data system for my website. As one of my XML files is quite large, I decided to try and break it into chunks.

I have added an .htaccess file that lets me do this:

`AddType text/xml .sxml
AddOutputFilter INCLUDES .sxml`

My .sxml files has certain includes in it, I’ve tested them in my browser and they work:
` <!–#include virtual=”./MainPage_Parts/Recording-Hymns_2022.txt”–>
<!–#include virtual=”./MainPage_Parts/Recording-SMGRiffChallenges.txt”–>
`

However, as far as my PHP is concerned, those sections of the files do not exist. Am I asking the impossible from my local server?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmFeb 16.2022 — Perhaps this is some syntax I am not familiar with but isnt the # sign a php comment?
Copy linkTweet thisAlerts:
@NogDogFeb 16.2022 — How is PHP accessing the XML file? Looks like for simplexml_load_file() you can specify LIBXML_XINCLUDE for the 3rd argument, which maybe would do what you need?
Copy linkTweet thisAlerts:
@tracknutFeb 16.2022 — Those are SSI formatted includes, and wouldn't work unless the XML was being parsed by your server as if it were html. Presumably you're not doing that other than when you just bring it up in a browser. When it's a data file being read by PHP, I don't actually know if there's an answer that works.

What I can offer is a brief description of what I do in a similar situation. I also use XML as the source for a site, and one of them is also quite big (1.5MB) if you're trying to edit it. I ended up deciding I needed a "build" tool, to take user-entered XML and do a whole bunch of things to it prior to putting it up live. One of these things is to merge sections, but it also validates data, adds things like image sizes and does some normalization of the structure for performance. This whole build process itself is controlled by (of course) an XML file, where I have the meta information about the file (author, descriptions, configuration info, languages included) as well as a series of <import> tags that reference the various files to be included.

I have found this build functionality to be super convenient, allowing me to not only edit on smaller parts of the file, but also to separate those things that need to happen when data is updated versus at run-time when users are browsing. Maybe you'll find this model useful, or maybe not, but I thought I'd offer it up to a fellow XML developer. :)
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorFeb 17.2022 — **NogDog:** I'm doing it through DOMDocument.

**Tracknut:** Yes, those are indeed SSI-formatted includes, which is why I used .htaccess to say ".sxml files are XML files that use SSI includes". While my files aren't quite THAT big (yet), I'll keep that in mind. :-)

Sorry for the lack of proper replies to the post, it seems this forum won't let me do actual replies. I get a red error message saying "You do not have permission to do that."
Copy linkTweet thisAlerts:
@NogDogFeb 17.2022 — Are you accessing the file via HTTP within you PHP script? (If you're using a file system path, then it's probably just loading the main file and ignoring the includes, since Apache -- and thus .htaccess -- would not be involved.)
Copy linkTweet thisAlerts:
@NogDogFeb 17.2022 — > @Mr_Initial_Man#1642578 As one of my XML files is quite large

As much as I know you love XML, this is sounding like a sign that maybe it's time to start thinking about using an actual database? ;)
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorFeb 17.2022 — Ah, I'm using a filesystem path, since I figured HTTP would take to long. And an actual database would make maintaining mirrors of my site a bit of a pain in the butt; at least with XML files, I can just make the changes to the local version, and upload the updated files to the other websites.

Also, tracknut, the more I read your suggestion, the more I like it--I do have XML files that crossreference each other, and using code to compile them into one massive file with its own special Document Type Definition is an interesting idea. :)
×

Success!

Help @Mr_Initial_Man spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...