Results 1 to 10 of 20

Thread: Why Choose PHP?

Threaded View

  1. #20
    Old-Fogey:Addicts founder Terr's Avatar
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    2,007
    Quote Originally Posted by niggles
    So do you mean, that instead of starting each page with

    session_start();
    $_POST = array_merge($_POST, $_GET);

    I can write a handler which automatically puts them at the top of each page?
    Basically. In an .htaccess file
    Code:
    Action handlemystuff /handler.php
    AddHandler handlemystuff .myext
    DirectoryIndex index.myext index.php index.html index.htm
    Then create index.myext:
    HTML Code:
    This is an index!
    <?php print("One plus one is :".(1+1)); ?>
    Then, in /handler.php:
    HTML Code:
    <?php
    $file = $_SERVER['PATH_INFO'];
    $path = $_SERVER['DOCUMENT_ROOT'].$file;
    session_start();
    $_POST = array_merge($_POST, $_GET);
    
    include("header.php");
    include($path);
    include("footer.php");
    ?>
    You will probably want to put something in .htaccess to make it so that people can't directly visit handler.php, as well as some extra checks (realpath() + substring comparison) to make sure that nobody is trying to pass you a PATH_INFO value which isn't in the right directories.

    Another benefit from this technique is that you can define another handler and another filetype, and pass in XML files which can be translated to HTML on the fly. Or you can do search-replace within the file, or set/unset various PHP variables depending on exactly where the file is located.
    Last edited by Terr; May 25th, 2007 at 04:44 AM.
    [HvC]Terr: L33T Technical Proficiency

Similar Threads

  1. PHP Flaws
    By SDK in forum Web Security
    Replies: 19
    Last Post: December 20th, 2004, 05:31 PM
  2. Tutorial: Apache 2.0.49 and PHP 4.3.7!
    By Vorlin in forum Other Tutorials Forum
    Replies: 3
    Last Post: June 15th, 2004, 10:25 PM
  3. Installing Apache and PHP on Linux
    By HDD in forum Other Tutorials Forum
    Replies: 2
    Last Post: February 1st, 2004, 08:05 PM
  4. flash for website !!!!!!!!!!!!!!
    By thuongtamnhan in forum AntiOnline's General Chit Chat
    Replies: 3
    Last Post: November 1st, 2003, 03:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •