SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Jul 2000
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in HTML files, you can use:
    <!--#exec cgi="script.cgi" -->
    and:
    <!--#include virtual="file.txt" -->

    so how do use both of these in a php file? Thanks


    ------------------
    ---
    Matt Dewinter
    Compucrap.com

  2. #2
    SitePoint Zealot
    Join Date
    May 2000
    Location
    Eugene, OR
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can include files in PHP using:

    <?php
    include("yourfile.inc");
    ?>

    I'm not sure how you execute a cgi script, other than just saying:

    echo("<!--#exec cgi="script.cgi" -->");

    Anybody else know?

  3. #3
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This should do the trick:

    passthru("script.cgi");

    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  4. #4
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have apache compiled as a module, most ISPs do. then try the following:
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    virtual ('cgitoexecute.cgi');
    [/code]
    I think I remember reading that it was slightly quicker to use virtual.

    ------------------
    Karl Austin
    KDA Web Services
    "Everyone has a photographic memory. Some just don't have film."

  5. #5
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kevin's suggestion above mine should work for you.

    ------------------
    Karl Austin
    KDA Web Services
    "Everyone has a photographic memory. Some just don't have film."

  6. #6
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    On one of my new servers,(it's a virtual server), my hosting company recently moved to php4. I thought Wonderful!
    I ran into a problem however that the call
    virtual ('cgitoexecute.cgi');
    didn't work!
    I emailed support and they told me that php was installed as cgi rather than apache module---so the virtual() call will not work.
    Does anyone know of a workaround? I really will appreciate the help/input.
    I need to be able to add polls etc. Thanks in advance, there's got to be a workaround?

  7. #7
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks Karl, but it didn't work. I am doing correctly aren't I?
    &lt;?
    passthru("/cgi-bin/cgi-script.pl");
    ?&gt;
    thanks. this is getting ridiculous.

  8. #8
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You need to specify the full path (including your home directory) for the passthru function. For example:

    passthru('/home/username/public_html/cgi-bin/cgi-script.pl');

    If this doesn't work, let us know what error message (if any) you are getting.

    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  9. #9
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First, let me say thanks for the help.
    Now, the bad part....it still doesn't work and doesn't give an error.
    This is Exactly what I have in place:

    &lt;?
    passthru("/home/tripsmarter/www/cgi-bin/qpoll31.pl?poll_id=999997&action=replace");
    ?&gt;

    Now, I know the poll script works, when inserted into an html page via ssi, it works like a champ.

    I'm stumped....any more ideas? (btw, I already have requests into the host to install PHP4 as an apache module---doesn't mean they'll do it---I'm hoping...) Still, I would like to know a solution, surely this has happened to someone else? I hope someone else can benefit from my troubles.

    thanks again all---I hope there's a solution.

  10. #10
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to make Kevins code a bit more portable you can use this instead:
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    passthru ( getenv ( 'DOCUMENT_ROOT' ).'/cgi-bin/cgi-script.pl' );
    [/code]

    As for the reason it is not working I don't know, what result is the passthru returning e.g. place echo in front of passthru and see what it prints out.

    ------------------
    Karl Austin
    KDA Web Services
    "Everyone has a photographic memory. Some just don't have film."

  11. #11
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The problem is that you're attempting to call your script with a query string, when in fact passthru() runs the script like a program. If you type

    /home/tripsmarter/www/cgi-bin/qpoll31.pl?poll_id=999997&action=replace

    on the Unix command line, it won't work, will it?

    The alternative is to load the script like a Web page in PHP and then incorporate the results into your page:

    $doc = fopen('http://localhost/cgi-bin/qpoll31.pl?poll_id=999997&action=replace','r');

    $docdata = fread($doc,1024*1024); // Read up to 1MB

    fclose($doc);

    echo($docdata);


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!


Bookmarks

Posting Permissions

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