Reply to Re: Single PHP file - *.php = process, *.phps = source.

Your name:

Reply:


Posted by Toby Inkster on 01/26/07 06:26

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

[Back to original 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

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