Include() with cgi problems

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

    Include() with cgi problems

    Dear friends,

    I have a big problem. With an usersonline script I need to extract in
    php the output of a cgi using buffering output in this way:

    <?php
    ob_start();
    include('/home/mysite/public_html/cgi-bin/usersonline/online.cgi');
    $contents = ob_get_contents ();
    ob_end_clean();
    echo $contents;
    ?>

    In this way the code of the cgi is displayed, not executed. Why? I need
    to execute and catch the output in this way...with
    include('http://www.mysite.com/cgi-bin/usersonline/online.cgi') works
    well but the requestes come with the same ip (my server) and this is
    not the results which I want.

    Thanks,

    Vincenzo, Rome, IT

  • Malcolm Dew-Jones

    #2
    Re: Include() with cgi problems

    VB (vincenzo.bacar ella@gmail.com) wrote:
    : Dear friends,

    : I have a big problem. With an usersonline script I need to extract in
    : php the output of a cgi using buffering output in this way:

    : <?php
    : ob_start();
    : include('/home/mysite/public_html/cgi-bin/usersonline/online.cgi');
    : In this way the code of the cgi is displayed, not executed. Why? I need
    : to execute and catch the output in this way...with
    : include('http://www.mysite.com/cgi-bin/usersonline/online.cgi') works
    : well but the requestes come with the same ip (my server) and this is
    : not the results which I want.

    You are including a file, so PHP reads the data into memory, and runs it
    as a php program (i.e. it looks for <?php ...?> tags and runs any php code
    it finds.)

    That is, in fact, identical to what happens using the "http://server..."
    syntax, except that the include gets the data from a different location.
    Instead of reading the data from a file handle, it reads the data from a
    socket handle. The socket is being sent the data from a web server.

    In both situations the include will check for <?php tags and maybe run the
    data as a php script.

    In neither situation does the include ever run the file as a cgi script.

    HOWEVER, since it's a local file, you can run it yourself using php
    functions such as

    exec() system() passthru() escapeshellcmd( ) pcntl_exec()
    system() backtick operator

    Look them up to check which would be best for you.

    THE ENVIRONMENT

    Because it is a cgi script it will expect certain environment variables to
    be set. But since php is already running in a cgi environment then you
    might not need to set any of the variables yourself - they are already
    set. Whether they have the correct values for the script will depend on
    what the script does. I would just give it a try and see what happens.

    --

    This programmer available for rent.

    Comment

    Working...