Custom php handler using Apache's mod_actions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tobias Hesselmann

    #1

    Custom php handler using Apache's mod_actions

    Hi folks,

    i have a problem using a PHP script as a custom handler in Apache.
    What i wanna do is this:

    Whenever a .html file is requested by a browser, i want Apache to call a
    CGI that outputs a header, then the requested file and then a footer.
    I want to use PHP for this, as i also want to do some template parsing.

    Well, basically, this can be done using Apache's mod_action module,
    where a custom handler can be defined for a certain filetype.
    This does work correctly. If i request a .html file, the handler is
    activated.

    The strange thing is this: PHP does not output anything but the html header!

    This is my custom handler file:
    ------------<htmlhandler.cg i>---------------
    #!/bin/bash
    /usr/bin/php-cgi test.php
    --------------------------------------------

    You see, php-cgi is called to execute test.php, which looks like this:

    ------------<test.php>----------------------
    <?php
    phpinfo();
    ?>
    --------------------------------------------

    So, what i would expect is, that the PHP info page is being sent to the
    browser, which is not the case. All that is sent back is the .html file
    i requested. And the strange thing is: If i execute the CGI from
    commandline, i get all the phpinfo output! It just doesn't work when
    called by apache!

    You might think that the handler is not activated at all, but it is,
    because if i change something in the custom handler config, like
    spelling the filename wrong, i get a server error.

    Also, i tried this using php-cgi directly, like this:

    ------------<htmlhandler.cg i>---------------
    #!/usr/bin/php-cgi
    <?php
    phpinfo();
    ?>
    --------------------------------------------
    Which just gives me back the exact same results (just the requested
    ..html file).


    Now for the funny part:
    I also tried to do this using bash commands, like this:
    ------------<htmlhandler.cg i>---------------
    #!/bin/bash
    echo "Content-Type: text/html"
    echo ""
    echo "Hello World"
    --------------------------------------------

    This one works!! Hello world is being sent to the browser!

    I am quite desperate, don't know what's left to try. Any ideas?
    By the way, i'm using Apache 2.0.40 and PHP 3.3.8.




    Thanks in Advance,

    Tobias
  • Tobias Hesselmann

    #2
    Re: Custom php handler using Apache's mod_actions

    Hi again,
    [color=blue]
    > By the way, i'm using Apache 2.0.40 and PHP 3.3.8.[/color]
    4.3.8 that is, as you might have figured out already ;)

    greets

    Tobias

    Comment

    • Guest's Avatar

      #3
      Re: Custom php handler using Apache's mod_actions

      > Whenever a .html file is requested by a browser, i want Apache to call a[color=blue]
      > CGI that outputs a header, then the requested file and then a footer.
      > I want to use PHP for this, as i also want to do some template parsing.[/color]

      Does it have to be a cgi that calls a PHP file? Can it just call a PHP file
      directly?
      If so, you can use the directives:

      auto_prepend_fi le
      auto_append_fil e

      for the header and footer respectively --

      _______________ _______________ ______
      Wil Moore III, MCP | Integrations Specialist


      Comment

      Working...