Re: Server Side Include translator as PHP functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Oct 8, 2011 at 2:31 PM, Complex <complex.confusion@xxxxxxxxx> wrote:

> On Sat, Oct 8, 2011 at 1:09 PM, Tommy Pham <tommyhp2@xxxxxxxxx> wrote:
>
> > I think you didn't provide enough details to get a more accurate
> suggestion
> > of a solution, but here goes...  Is 'include SSI file B' always included
> and
> > always need to be replaced?  If so, that's a very apparent solution.  If
> > not, what are criterias?  URL? Query parameter(s) and/or value(s)?
> Certain
> > user(s)?  Certain group(s) of users?  Certain hour of the day?  Certain
> user
> > agent(s)? etc...  Regardless of how dynamic any site is, there's a always
> > some kind of pattern.  What you need to do is identify that pattern and
> do
> > what you need accordingly.  What about having PHP read those files to be
> > included and output without having to rely on SSI mechanisms?
> >
> > I'm just curious... since PHP is OOP and, IIRC of SSI, the use of SSI
> limits
> > the full potential of OOP and PHP.  Is the control of the application and
> > configurations beyond yours?
> >
> > Regards,
> > Tommy
> >
>
> Tommy,
> Last question first: yes, using SSI limits the full potential of the
> PHP being used, but the point of this exercise is to continue using
> the existing SSI includes for this small subsection of the larger
> website, and to not recode the larger whole to benefit the smaller
> piece. Make whatever Star Trekism of that  you will; we simply don't
> have time or resources to use PHP everywhere as we should.
>
>
Then you should seriously consider the site's function and features and see
if the current application fits that model.  Doing little patchwork here and
there may end up costing a lot more time and resources than just rewriting
the application in PHP, IMO, not to mention losing customer/clients because
of buggy application due to patchworks.  I'm sure some experienced folks
here have been through that at some point, myself included - which is why I
stop using ASP and SSI and moved on to OOP over 10 years ago.

I do not understand your question about criteria; the only criteria
> for these Apache Server Side Includes is the relative (or
> relative-to-root) filepath:
>   <!--#include virtual="/includes/header-pieces/A.inc" -->
> If you mean, which server variables am I accessing with SSI and now
> need to access with PHP, I'm primarily concerned with the current
> filepath.
>
> "SSI include file B" is, in this case, the contents of an HTML
> webpage's HEAD block. The PHP-based CMS can fill the HEAD with some
> useful info unique to the current page. If I can achieve the _actual
> problem_ of translating the SSI commands into PHP, it would be a
> simple matter for me to insert some additional material into the
> middle of the original. The only reason I even mention this simple
> problem is because it explains why I"m bothering to do this at all. If
> all I wanted was to get the unaltered output of the SSI includes, I'd
> just continue doing <?php include("/includes/header-pieces/A.inc"); ?>
> and be on my way.
>
> All I want to know is if someone has already written a set of
> functions to translate some if not all SSI commands into PHP.
>     e.g.    <!--#include virtual="/includes/header-pieces/A.inc" -->
>  becomes <?php include("/includes/header-pieces/A.inc"); ?>
>               <!--#set var="foo" value="bar" --> becomes <?php var
> foo = "bar"; ?>
>               <!--#if expr="${foo}" -->...<!--#elif expr="${bar}"
> -->...<!--#else -->...<!--#endif -->
>               <?php if($foo) {...} elseif($bar) {...} else {...} ?>
> Otherwise, I have to write those functions myself and, inevitably,
> spend time I don't have getting it right. I've searched, but I may
> easily have missed or not recognized the functions that I need.
>
>
> --
> --> CC <---
>

* Case 1 of always include and always replace (and not modifying headers):

change  <!--#include virtual="/includes/old/file/B.inc" -->
to <!--#include virtual="/path/to/php/code2exec.php" -->

* Anything else, if I'm reading it correctly:

Incoming request -> static HTML file -> SSI mechanism (included some files)

change the above flow to (there by passing SSI mechanism)

Incoming request -> PHP file index.php (include some files, execute PHP
scripts as needed and change the httpd configurations accordingly)

or

Incoming request -> SSI mechanism (included some files)

change the above flow to (there by passing SSI mechanism)

<!--#include virtual="/path/to/php/file/handlingRequests.php" --> or just
remove the SSI mechanism altogether and have a index.php file doing all the
work and thus reducing the complex configuration and application flow, and
server overhead.  (Migrating the SSI configurations in httpd to PHP codes
shouldn't take that long unless you're new to PHP.)

--- the file handlingRequests.php or index.php would look something akin to
below.

<?php
include_once('/path/to/header.inc');
// psuedo code
// if condition A (looking to match certain query parameter name & value [1]
//    or certain user agents [2]) then
//    include ('/path/to/file/conditionA.inc');
// elseif condition B (whatever else condition you're looking for)
//    execute PHP codes or include a PHP file to execute codes
// else
//    do nothing or executing some other PHP codes
// end if block
include_once('/path/to/footer.inc');

Note:  if you need to set headers, then change the include_once to have PHP
read [3] the contents into a variable and echo/print out accordingly later.


The above change can be implemented for all or just sections (of URLs) you
want to change depending on site/application flow.  Simply, you're replacing
SSI doing the legwork of just including files with PHP including files and
execute some codes.  The index.php file handling all requests would be
something like this:

<?php
$header = file_get_contents('/path/to/header.inc'); /* [3] */
$path = pathinfo($_SERVER['REQUEST_URI'], PATHINFO_DIRNAME); /* [4] */
if (!$condition_B))
{
  if (file_exists($path.'/body.inc')) include_once($path.'/body.inc');
  else $redirect_404_or_what_ever_you_want_here;
} else
{
  /* execute your php code here, including setting setting headers, that
doesn't echo/print anything */
}
$footer = file_get_contents('/path/to/footer.inc');

echo $header, $content_generated_from_PHP_code, $footer


Regards,
Tommy


[1] $_GET, $_REQUEST, $_POST in php.net/reserved.variables
[2] $_SERVER in php.net/reserved.variables
[3] php.net/ref.filesystem
[4] php.net/function.pathinfo

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux