You are here: Re: Single PHP file - *.php = process, *.phps = source. « PHP Programming Language « IT news, forums, messages
Re: Single PHP file - *.php = process, *.phps = source.

Posted by Rik on 01/26/07 01:15

On Fri, 26 Jan 2007 02:04:18 +0100, Lucanos <lucanos@gmail.com> wrote:

> 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.php" 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_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация