|
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
Navigation:
[Reply to this message]
|