f



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.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.

Thanks

0
lucanos (16)
1/26/2007 1:04:18 AM
comp.lang.php 32646 articles. 0 followers. Post Follow

3 Replies
958 Views

Similar Articles

[PageSpeed] 26

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
0
1/26/2007 1:15:32 AM
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.phps", 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_FILENAME']);
			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

0
1/26/2007 6:26:14 AM
> 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 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
0
nospam30 (870)
1/26/2007 9:52:36 AM
Reply:

Similar Artilces:

object files, header files, source files?
I can't find any books describing the anatomy of C/C++ programs. What is an object file? Can it be generated from a header file?, what is linking?, why does a source file need an object file? etc. I have looked in The C programming Language, The C++ Programming Language, Accelerated C++, GNU make etc but they don't describe these basic subject. Any literature that covers these subjects? saneman wrote: > I can't find any books describing the anatomy of C/C++ programs. What is > an object file? Can it be generated from a header file?, what is > linking?, why does a s...

Cannot open the TeX source file:The DVI file contains no source links??
I don't know what's wrong with my WinEdt, recently, I always get the following message when I click the DVI file : Cannot open the TeX source file: The DVI file contains no source links$B!#(B Click help, then the following message: Use the -src-specials option the next time you compile your TeX source file$B!#(B Still don't know how to fix it. Help! On Dec 25, 6:26 pm, zhu...@gmail.com wrote: > I don't know what's wrong with my WinEdt, recently, I always get the > following message when I click the DVI file : > > Cannot open the TeX source file: The DVI file contains no source > links$B!#(B > > Click help, then the following message: > > Use the -src-specials option the next time you compile your TeX source > file$B!#(B > > Still don't know how to fix it. Help! In the WinEdt widow, at the bottom, there are various boxes. In between the one that should say "TeX" and the one with the name of the current project (by default WinEdt.prj), you should have something saying "--src". If it's empty, try clicking it and see if "--src" appears. Joseph Wright ...

RfD: FILE-SOURCE STRING-SOURCE and CLOSE-SOURCE
Two or three weeks ago I said I would write this RfD. Problem ~~~~~~~ To handle text from different types of input sources ANS Forth provides various words such as SOURCE SOURCE-ID REFILL >IN PARSE WORD SAVE-INPUT RESTORE-INPUT and the Forth 200X PARSE-NAME. In addition other parsing words such as CREATE ' etc work on the current input source. Many applications use the File-Access word set to handle text files and, having opened a file, can't immediately use words such as REFILL on that file. This is because the words ANS Forth provides for opening new input sources (INCLUDE-FILE ...

Restore from a single file crated with "Extract all messages to a single file"
Hi If I chose to "Save message(s) to file(s)" and then "Extract all messages to a single file" how can I import this file to a mail folder again? Regards Carsten On Wed, 23 Mar 2005 10:15:28 +0100, Carsten <mail@no-mail.dk> wrote: > Hi > If I chose to "Save message(s) to file(s)" and then "Extract all > messages to a single file" how can I import this file to a mail folder > again? No way other than extracting each single message into a *.cnm file and moving these into your mailbox directory so they will show...

Source distribution, source file settings, files not goint to the desired destination directory
I am tring to set up a number of source distributions for a handful of unique but related programs in LabView 8.0.1.&nbsp; All of the programs&nbsp;have their own unique tasks to comple but they all use a set of basic sub vi's that I wrote.&nbsp; Basically I could have put all those sub vi's into a .lib file but chose not to for the sake of simplicity.&nbsp; Also each program calls a number of vi's from the set of LabView libraries.&nbsp; To summarize what I want to do with my distribution structure;&nbsp;I created four destination&nbsp;directories: First the top level destination directory, the top level vi of each program will live there.&nbsp; Second I made the Support Directory which&nbsp;contains all of the unique sub vi's&nbsp;that are required by the top level vi.&nbsp; Third I mad a Common Support directory which will contain all of the basic sub vi's that all of my programs use. And fourth I made a Library Support&nbsp;directory which will contain all&nbsp;LabView&nbsp;library vi's.&nbsp;&nbsp;The top level destination directory is superior to the other three directories and the other three directories are at a pier level. &nbsp; My problem is when I assign the locations for the vi's in the Source File Setting category. The destination directory for all of my Dependencies vi's (basically all of the LabView library vi's)&nbsp;is not obeyed.&nbsp; I want all ...

Multiple processes writing to a single file
I need to write to a single file from multiple processes (e.g. parallel make). One approach is creating a lock file while the file is being updated, so that other processes won't be able to write. Once it's done, the program (or script) removes the lock file and others can write to the file. In practice, I have problems dealing with the existence of the lock file. and the file gets corrupted. How can I do it? Is there a useful link, etc? Thanks. James James <hslee911@yahoo.com> wrote: > I need to write to a single file from multiple processes > (e.g. parallel make). >...

Multiple processes logging to single file
When using the native ruby logger, is it save to have multiple processes writing to the same log file? For instance, I have the following ruby source example: # test.rb require 'logger' log = Logger.new('/tmp/RLOG') 20.times do log.error "PID: #{$$}" sleep 1 end log.close # end test.rb Then I execute like so: $ ruby test.rb & ruby test.rb & ruby test.rb After inspection of the log file, each process logged 20 times, all messages interleaved of course. It looks like it works, but am I delusional? I'm on an OpenBSD box. Does the OS handle caching...

Multiple Jobs to Process single file
Hi, I have a question regarding using the same program in parallel to process large files. Basically, I have a large file that is processed by a single program to produce multiple summarized files. I have a CL which retrieves the number of records in the file and then submits the same program four times with a starting RRN and the number of records to process. The submitted program does a position and then process the number of records asked for. Everything works fine. As always I'd like to generalize this even more. It would be ideal if I did not have to pass t...

Single questions about file processing in perl
Hello all! The following code is correct : open(FD,"< my.txt") or die("Error"); while(<FD>) { print "$_\n"; exit(0) if ($_eq "STOP"); } But this code work incorrect : open(FD,"< my.txt") or die("Error"); $_="NOT_STOP"; while(<FD> and ($_ne "STOP") ) { print "$_\n"; } print "$_\n"; exit(0); Both example are equivalent? Or I wrong? Furthermore, why this code is incorrect : while(<FD> and 1) { print "$_\n"; } Thanks! dima@inotech.ru wrote: > Hello...

What is a source file and what is a binary file?
Dear Sir: What is a source file and what is a binary file? I want to install a program which has rpm package available. But it has two links: one is "source rpm", another is "binary rpm". Which one should I download and use rpm command "rpm -Uvh foo.rpm" to install it? Thank you very much. Best Regards, Xiaoshen Xiaoshen Li <xli6@gmu.edu> wrote: > Dear Sir: > What is a source file and what is a binary file? I want to install a > program which has rpm package available. But it has two links: one is > "source rpm", another is &...

Import Multiple Excel Files into Multiple files or One Single File
I was fiddling around with the code below: cd('C:\Users\Excel\Desktop\Excel_Files') d = dir('*.xls'); nfiles = length(d); data = []; for k = 1:nfiles num = xlsread(d(k).name); end It seems to import all files, but overwrites the data in the file, so only the last file imported is actually stored in the Matlab variable. I am trying to figure out a way to import multiple files into multiple Matlab variables. Also, I am trying to figure out a way to import multiple files into one single Matlab variable. Can someone here give me the code to do that? Thanks!! On 11/25/2012 11:06 PM, Ryan wrote: > I was fiddling around with the code below: > cd('C:\Users\Excel\Desktop\Excel_Files') > d = dir('*.xls'); > nfiles = length(d); > data = []; > for k = 1:nfiles > num = xlsread(d(k).name); > end > > It seems to import all files, but overwrites the data in the file, so only the last >file imported is actually stored in the Matlab variable. > Well. Yes. That is what you telling Matlab to do. You are writing num = xlsread(d(k).name); And Matlab is doing just that. It puts the content of d(k).name into num. see recent thread 'Re: How to Import Several Text Files Into Matlab?' may be that will help. ...

Mix different C source files into a single one
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 program able to do this kind of task ? Thanks "Horacius ReX" <horacius.rex@gmail.com> wrote in message > 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 o...

I was lost /usr/etc/rc Now I can not find source of this file in internet. Take me please source of this file.
Hello all. I was lost /usr/etc/rc Now I can not find source of this file in internet. Take me please source of this file. Thank you. http://www.minix3.ru/forum_files/rc ...

Import Multiple Excel Files into Multiple files or One Single File #2
Now, the code below seems ok to me, but when I run it, I get this error: Error in read_all_files_in_folder (line 27) xlswrite(fOut, numData, s); numData: empty 0x0 double %folders = {'C:\Users\Excel\Desktop\Excel_Files\'}; %# get input XLS files dName = uigetdir('.', 'Select folder containing Excel XLS files'); if dName==0, error('No folder selected'); end files = dir( fullfile(dName,'*.xls') ); files = strcat(dName, filesep, {files.name}'); %' %# prepare output XLS file [fName dName] = uiputfile({'*.xls' 'Excel (*.xls)'}, 'Output File', 'final.xls'); if dName==0, error('No file selected'); end fOut = fullfile(dName,fName); %# process NUM_SHEETS = 1; %# number of sheets per file for s=1:NUM_SHEETS %# extract contents of same sheet from all files numData = cell(numel(files),1); for f=1:numel(files) numData{f} = xlsread(files{f}, s); end %# rearrange data numData = cat(3,numData{:}); numData = reshape(permute(numData,[3 1 2]), [], size(numData,2)); %# write data to corresponding sheet of output XLS file xlswrite(fOut, numData, s); end How can I modify this code to import all files in the folder into separate variables (any number of Excel files become any number of Matlab variables)? Also, how can I make the code import everything into one single variable (all data in f...

Java classes are always defined inside a single source code file ?!
Hi ! "Java classes are always defined inside a single source code file." I have found the above afirmation in the book "Java 2 programmer Exam Cram 2 (310-035)". However I am able to do something like this in a single file: public class CTest { public static void main( String[] args ) throws Exception { System.out.println("This is CTest !"); } } class Mebo { public static void main( String[] args ) { System.out.println("This is MEBO !"); } } Pay attention: the class Mebo is not public (it has package access). However, after com...

about the header file and source file in C++
Sorry about the beginners question In the header file, each time you define a class or function, it has to be followed by a semicolon. But in the source file, the functions do not have to be followed by semicolon. What is the reason for this? Thanks stonny wrote: > Sorry about the beginners question > > In the header file, each time you define a class or function, it has > to be followed by a semicolon. > But in the source file, the functions do not have to be followed by > semicolon. No. There should be no semicolons after a function body anywhere. Inside a class def...

how to run multiple processes from a single process?
Hi all, I am porting a win32 c++ program on Linux which first reads a list of processes and their paths from a file.Then this program should launch all of thesese processes. I tried to achieve this using fork() and execv() API calls. but execv() method call is synchronous and does not return untill user closes the child application or a launch program error occurs. Is there any other API / alternate solution available in Linux C++? Thanks in advance. [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] ...

Merging all files into single LaTeX file
Dear all, I want to merge all individual files into single LaTeX file. For this purpose, I used the below commands to meet my requirement. **************************** \documentclass{book} \begin{document} \bibligraphystyle{plain} \begin{document} \include{ch01} \bibliography{ch01bib} \include{ch02} \bibliography{ch02bib} .... \end{document} *********************** The above coding meets my requirement successfully except reference part. While running bibTeX, it accepted the first .bib file only, the second input .bib file was rejected. I also attached the .blg output below: This is BibTeX, Version 0.99cThe top-level auxiliary file: x:\sar_m\bib \main.aux The style file: plain.bst A level-1 auxiliary file: ./1/ch01.aux Illegal, another \bibdata command---line 4 of file x:\sar_m\bib \main.aux : \bibdata : {ch01bib} I'm skipping whatever remains of this command A level-1 auxiliary file: ./2/ch02.aux Illegal, another \bibdata command---line 6 of file x:\sar_m\bib \main.aux : \bibdata : {ch02bib} I'm skipping whatever remains of this command Database file #1: ch01bib.bib Warning--I didn't find a database entry for "katzen2000" ..... ..... Kindly suggest me how to achive my requirement. Thankx and Regards, Saravanan,M. TeX_Saravanan wrote: > Dear all, > > I want to merge all individual files into single LaTeX file. For this > purpose, I used the below commands to meet my requirement. > > *******************...

how to run multiple processes from a single process?
Hi all, I am porting a win32 c++ program on Linux which first reads a list of processes and their paths from a file.Then this program should launch all of thesese processes. I tried to achieve this using fork() and execv() API calls. but execv() method call is synchronous and does not return untill user closes the child application or a launch program error occurs. which means only first process will run. Is there any other API / alternate solution available in Linux C++? Thanks in advance. mandydhaliwal@gmail.com wrote: > Hi all, > > I am porting a win32...

process cannot access the file because it is being used by other process
Hi, i am using below code ,it works fine on ordinary python 26 ,but when i use this script in my python testing tool it gives me message "process cannot access the file because it is being used by other process" for the second time invoking of mongoose server. Please help me in handling this exception. def invoke_server2(): file = open("mongoose-2.8.exe", "r") try: proc = subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D: \372\pythonweb\mongoose-2.8.exe -root D:\New1\ >YourOutput.txt"') except OSError: print "os error" file.close() sys.exc_clear() os.remove("mongoose-2.8.exe") def invoke_server3(): file = open("mongoose-2.8.exe", "r") try: proc = subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D: \372\pythonweb\mongoose-2.8.exe -root D:\New2\ >YourOutput.txt"') except OSError: print "os error" file.close() sys.exc_clear() os.remove("mongoose-2.8.exe") def kill_server(): killret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /c "taskkill /F /IM mongoose-2.8.exe >YourOutput1.txt"') print killret invoke_server1() time.sleep(5) kill_server() time.sleep(5) invoke_server2() time.sleep(5) kill_server() time.sleep(5) invoke_server3() time.sleep(5) kill_server() O...

writing different file to a single file
Dear Friends, I have three spectra in three different file (spec1.txt, spec2.txt and spec3.txt). They ranges from 100-200A, 200-300A and 300-400A. Does anybody knows how I can write them in a single file in a right order. thanks in advance On Thursday, July 24, 2014 7:26:55 PM UTC-4, idlhelp wrote: > Dear Friends, > > I have three spectra in three different file (spec1.txt, spec2.txt and spec3.txt). They ranges from 100-200A, 200-300A and 300-400A. Does anybody knows how I can write them in a single file in a right order. > > > &...

cannot delete file
cannot delete file - http://LongPathTool.com can fix it Do you have error messages?, like : Path too long. Error cannot delete file: cannot read from source file or disk Cannot delete file: Access is denied There has been a sharing violation. Cannot delete file or folder The file name you specified is not valid or too long. Specify a different file name. The source or destination file may be in use. The file is in use by another program or user. Error Deleting File or Folder Make sure the disk is not full or write-protected and that the file is not currently in use. Error Copy...

cannot delete file
cannot delete file - http://LongPathTool.com can fix it Do you have error messages?, like : Path too long. Error cannot delete file: cannot read from source file or disk Cannot delete file: Access is denied There has been a sharing violation. Cannot delete file or folder The file name you specified is not valid or too long. Specify a different file name. The source or destination file may be in use. The file is in use by another program or user. Error Deleting File or Folder Make sure the disk is not full or write-protected and that the file is not currently in use. Error Copy...

batch file processing of text files in matlab
Hi, Can somebody guide me if we can do batch processing on text files in matlab..if yes, any guidelines will be appreciated.. Cordially, safee ...

Displaying information in the log file about which file is being processed
Hi! I figure that if I could write a macro and let the start of each file that are being processed during the execution of a program telling the user which file SAS is processing at the moment, then it would make it easier to find and debug the program when errors or warnings occur. It doesn't necessarily have to be a macro, but the convenience of a macro is that it doesn't take much place when it is called, just one or two lines of code. For example: %find_filename %display_filename_in_log(&this_file) Below is an example of code. It can easily be enclosed in a macro. This can for instance be (part of) the content in the macro %DISPLAY_FILENAME_IN_LOG(this_file). data _null_; do; put "NOTE: ***************************************************************"; put "NOTE: * The file being executed at the moment is named '&File_001' "; put "NOTE: ***************************************************************"; end; run; But SAS has no chance to know that &FILE_001 resolves to for example 'C:\TEMP\test.sas'. Is it a way that SAS can catch this metadata information so i can assign it to the value of the macro variable %let THE_PRESENT_FILE_EXECUTED? I guess SAS by default tells which file is being processed, but what I am looking for is a more conspiuous way to tell the programmer this information, so that errors can be faster to track. I wouldn't be surprised if there ...

Web resources about - Single PHP file - *.php = process, *.phps = source. - comp.lang.php

Stationary process - Wikipedia, the free encyclopedia
In the mathematical sciences , a stationary process (or strict(ly) stationary process or strong(ly) stationary process ) is a stochastic process ...

Indonesia says Bali Process failure on refugee crisis "must not happen again"
Indonesian Foreign Minister Retno Marsudi issues a blunt warning as Julie Bishop insists Australia is doing its share on refugees.

LastPass Authenticator for iOS launches to improve the two-factor authentication process
Security-minded individuals looking to simplify their two-factor authentication logins may want to take a look at LastPass’s new app today, LastPass ...

Intel’s ‘Tick-Tock’ Seemingly Dead, Becomes ‘Process-Architecture-Optimization’
... Fool , Intel’s latest 10-K / annual report filing would seem to suggest that the ‘Tick-Tock’ strategy of introducing a new lithographic process ...

Intel retires “tick-tock” development model, extending the life of each process
The third phase after tock finally has a name. It looks like the Kaby Lake processor isn't a one-off. Intel's latest 10-K filing (spotted at ...

An eHarmony-for-marketers has launched to make the process of choosing ad agencies less painful
A new business matchmaking company that describes itself as the "first and only" service that uses algorithmic science to match businesses with ...

Tesla Spills The Beans On The Model 3 Reservation Process
... in Hawthorne. It’s a bit crazy, actually, that people are getting so crazy [&hellip Tesla Spills The Beans On The Model 3 Reservation Process ...

Assimilation is a long process for Somalis in US farm town
... eastern plains. They've started a small halal mini-market and a restaurant, sent their children to the schools and worked at a meat processing ...

The Republican Party’s Delegate Allocation Process Is Totally Bonkers
Voters in the Mariana Islands have immense power, those in North Dakota none at all

SCOTUS Chief Justice John Roberts criticized partisan confirmation process before Scalia's death
... of all, Roberts doesn't it want it to be remembered that way. That's part of what was behind Roberts' criticism of the confirmation process ...

Resources last updated: 3/23/2016 9:02:59 PM