Jump to content
Karaethon

Parsing pages that DON'T end in .php

Recommended Posts

Posted (edited)

How/where is the setting that tells PHP which pages to parse? Does Apache have it and sends the file to the PHP engine? I have a custom extension that I am using and the server isnt parsing it because its not php extension.

Edited by Karaethon
Typo Correction

Share this post


Link to post
Share on other sites

Apache doesn't magically know that .php files go through PHP. That has to be configured. And the very same configuration that says the .php extension goes through PHP can be modified to say that other extensions do too.

Share this post


Link to post
Share on other sites

Yup, I kinda remembered something about that when I was learning how to install Apachee/php/mysql but I don't remember how/where it is or how to set it.

Share this post


Link to post
Share on other sites

mod_php and php-fpm work differently. For the former it's in the server configuration, for the latter it's in the site configuration.

Share this post


Link to post
Share on other sites

Ok, i remember Mod_php by name but I still dont remember how to set it to parse my files. is it something I can do in .htaccess? or should I rename all my fules and adjust all my pages?

Share this post


Link to post
Share on other sites

Find the configuration and change it to allow your extensions.

If you don't want to bother because you don't happen to remember exactly what it is you need to change or where then give up and do something else with your time.

Share this post


Link to post
Share on other sites

I looked at everthing settings related and I cant find the setting for it. But I decided it's not hard to change the file to standard php extension so thats better, especially since I may not be able to edit settings on final server.

Share this post


Link to post
Share on other sites

The association with a handler and files of an extension or specific name is part of the apache configuration.  

There are actually a couple of different ways of doing it, and some potential security ramifications which are discussed in this blog post.  It is possible to make these settings in an .htaccess file if the server has been configured to allow it.

<FilesMatch \.foo$>
SetHandler application/x-httpd-php
</Files>

This block would need to be inside a directory block if it's in an apache config for a vhost, but would be fine in an .htaccess.  Note the basic regex which insures that myfile.foo will get parsed as php, but myfile.foo.jpg will not.  This was a common exploit used to attack apache servers with php applications which allow uploads of images for example.  

Share this post


Link to post
Share on other sites

The one thing that hasn't been mentioned is WHY would YOU want to do this in the first place?

Share this post


Link to post
Share on other sites
4 hours ago, benanamen said:

The one thing that hasn't been mentioned is WHY would YOU want to do this in the first place?

Its kinda silly. I have code snippets, pieces of code that i use often in several places, so i save them as .snip, when I include them they run php code but i needed to call one via ajax and it wasnt running php code because it wasnt .php 

i finally realized that giving it a ohp extension was the logical, least effort, option.

Share this post


Link to post
Share on other sites
On 6/28/2019 at 8:25 PM, Karaethon said:

Its kinda silly. I have code snippets, pieces of code that i use often in several places, so i save them as .snip, when I include them they run php code but i needed to call one via ajax and it wasnt running php code because it wasnt .php

Don't do that. Make a page specifically for the AJAX request that "calls" the snippet.

And just stick with .php. It's more portable, both for running and for editing. If you want your snippets (I term I hate, by the way) to be separate then put them in a dedicated directory or something.

Share this post


Link to post
Share on other sites
On 7/2/2019 at 8:58 AM, requinix said:

Don't do that. Make a page specifically for the AJAX request that "calls" the snippet.

And just stick with .php. It's more portable, both for running and for editing. If you want your snippets (I term I hate, by the way) to be separate then put them in a dedicated directory or something.

Yeah, thats what I ended up doing. and why hate 'snippets'? thats what they are, pieces of html that by themselves are just a piece of the whole page. like footer, header, menu, etc. what would you call them? pieces? chunks? (truffle shufle)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.