473,804 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Single PHP file - *.php = process, *.phps = source.

Hi All,

Hoping for some direction here (I have searched, without avail, for a
solution already).

I was toying with trying to find a way whereby I could have a single
PHP file, and then specify whether to either see the processed output
or the source code by using the extensions php and phps (respectively).

So, with one file called "theFile.ph p" on the server, going to
"www.server .com/theFile.php" would show the end result of the php
actions, whereas going to "www.server .com/theFile.phps" would show the
actual content of the file itself.

I thought this could be done by modifying the htaccess file as follows:

AddType application/x-httpd-php-source phps

RewriteEngine on
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
RewriteRule ^(.+)\.phps$ $1.php

However this does not work:
- if a *.php file exists, then accessing *.php or *.phps returns the
end result of the php actions.
- if a *.phps file exists, then accessing *.php returns a 404 error,
and *.phps shows the actual file contents.

Looking for any direction, references, or assistance.

Thanks

Jan 26 '07 #1
3 2072
Rik
On Fri, 26 Jan 2007 02:04:18 +0100, Lucanos <lu*****@gmail. comwrote:
Hi All,

Hoping for some direction here (I have searched, without avail, for a
solution already).

I was toying with trying to find a way whereby I could have a single
PHP file, and then specify whether to either see the processed output
or the source code by using the extensions php and phps (respectively).

So, with one file called "theFile.ph p" on the server, going to
"www.server .com/theFile.php" would show the end result of the php
actions, whereas going to "www.server .com/theFile.phps" would show the
actual content of the file itself.

I thought this could be done by modifying the htaccess file as follows:

AddType application/x-httpd-php-source phps

RewriteEngine on
RewriteCond %{REQUEST_FILEN AME} !-f
RewriteCond %{REQUEST_FILEN AME} !-d
RewriteRule ^(.+)\.phps$ $1.php

However this does not work:
- if a *.php file exists, then accessing *.php or *.phps returns the
end result of the php actions.
- if a *.phps file exists, then accessing *.php returns a 404 error,
and *.phps shows the actual file contents.

Looking for any direction, references, or assistance.
First of all, let's make it clear that what you want is a major, major
security risk... Add very rigid security fot the ones allowed to see the
code, both in authenticating and in what directories they are allowed to
see.
Now, for your solution:

Make 2 files:
----highlighter.php-----
highlight_file( $_GET['file']);
------------------------

---.htaccess:-----------
RewriteCond $1.php -f
RewriteCond $1.phps !-f
RewriteRule ^(.*)\.phps$ highlighter.php ?file=$1
------------------------

Voilà.
--
Rik Wasmus
Jan 26 '07 #2
Lucanos wrote:
I was toying with trying to find a way whereby I could have a single
PHP file, and then specify whether to either see the processed output
or the source code by using the extensions php and phps (respectively).
As Rik said, for production code this can cause security problems. Of
course, properly secured code doesn't rely on security-through-obscurity,
but still, obscurity helps sometimes.

That said, I often use it as a technique when posting example code for
people.

Method one: symbolic links. Create the file mycode.php, then create a
symbolic link to it using the following command and the command line:

ln -s mycode.php mycode.phps

This effectively creates two copies of the file, one called "mycode.php "
and one called "mycode.php s", but any updates to the PHP file will also
show up in the PHPS file.

Method two: PHP. Add the following code to the top of each PHP file:

<?php
if ($_GET['source'])
{
highlight_file( $_SERVER['SCRIPT_FILENAM E']);
exit();
}
?>

You can now add "?source=1" to a URL to show its source.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jan 26 '07 #3
I was toying with trying to find a way whereby I could have a single
PHP file, and then specify whether to either see the processed output
or the source code by using the extensions php and phps (respectively).

So, with one file called "theFile.ph p" on the server, going to
"www.server .com/theFile.php" would show the end result of the php
actions, whereas going to "www.server .com/theFile.phps" would show the
actual content of the file itself.

I would do this in another way: create a PHP script that takes a
filename as a parameter, checks this to see if it is a file that is
allowed to be seen, and sends the contents of the file as plaintext to
the browser.

You would call it with something like
www.server.com/showsource?file=theFile.php

Of course, you can instruct apache to turn that into any other URL with
rewriting.

Best regards
Jan 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2953
by: LP | last post by:
Hi, I have a site which runs on .Net technology. The site is already deployed and running. I need to change 1 file for some small enhancement. Please tell me, how can I compile that 1 file and merge it to the original DLL (the one deployed on the live server) so as to upgrade it. I dont want to recompile the whole project for the 1 file Regards,. LP
2
3731
by: Jerry | last post by:
Hi all! I have a small website and am having a slight difficulty keeping up with the changes needed to keep it current and fresh. I have a lot a archived pages that I'd like to rotate maybe in case I haven't prepared a new days worth of content. What I'm asking... ....is it possible to access html files on my files on my hosted site's server for the simple process of copying and pasting the code into another newly created file prior to...
9
6642
by: Aguilar, James | last post by:
I know that one can define an essentially unlimited number of classes in a file. And one can declare just as many in a header file. However, the question I have is, should I? Suppose that, to use the common example, I have a situation where I am implementing many types of Shapes. My current way of thinking is, well, since they are all the same type, let's just put them all in the same file. The include file would be "shapes.h" and it...
10
2318
by: Tim Mulholland | last post by:
My company is about to begin working on an ASP.NET application. There are going to be two primary developers working on this project. It will be a fairly deep project (lots of lines of code) but not a very wide project (pretty much limited to a few purposes, not many ways to split it up). I've done alot of ASP.NET development before by myself so writing the application shouldn't be an issue, but my question is this: How do multiple...
3
1979
by: Disco Octopus | last post by:
Hi, Does anyone know if there is a way to get something equivilent to this... AddType application/x-httpd-php-source .phps .... to work for IIS? Thanks
0
2037
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers said to me that they have no problem doing that, but the following project file is said to be corrupted while opening in the IDE, it is the project file of NT xemacs BETA 21.5.24, http://ftp.xemacs.org/pub/beta/xemacs-21.5.24.tar.gz (under the...
6
1500
by: Raistlin Majere | last post by:
I have Apache/MySQL/PHP on Windows XP. I want my PHP files to behave in my computer like in web host. I open a PHP file with FF and its content is printed!
4
4478
by: Alan Mailer | last post by:
Again, I'm new to VB.net and there is something I need help with: Like (I assume) many of us, over time I want to be able to create some VB.net classes that I might want to use in more than one Project. So let's say I've created a Folder called "MyVBNet Classes" to hold these general-use VB.Net class files that I will eventually associate with various Projects I create. Now let's imagine I've created a class called "MyClass.vb" that...
4
1231
by: Horacius ReX | last post by:
Hi, I have a C program split into different source files. I am trying a new compiler and for some reason it only accepts a single source file. So I need to "mix" all my different C source files into a single one. Do you know about some type of python script able to do this kind of task ? Thanks
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.