SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Dec 2003
    Location
    USA
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    include return value of a PHP file on a different server

    Hi, I have a PHP file that includes a remote PHP file on a different server (in order to run the included file on the server its on).

    I need to return a status value to the including PHP file (lets say that value can be "result-1", "result-2" or "result-3"). I could not figure out how I can do that.

    The following is what the PHP manual states:
    ..... This is not, however, possible when including remote files unless the output of the remote file has valid PHP start and end tags (as with any local file). You can declare the needed variables within those tags and they will be introduced at whichever point the file was included.
    Based on my undertanding, I declared a variable in the remote PHP file but that variable did not have that value in the including PHP file on the line just after the include statement. Did I miss-understand the PHP manual ?

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by salam
    Hi, I have a PHP file that includes a remote PHP file on a different server (in order to run the included file on the server its on).

    I need to return a status value to the including PHP file (lets say that value can be "result-1", "result-2" or "result-3"). I could not figure out how I can do that.

    The following is what the PHP manual states:
    Based on my undertanding, I declared a variable in the remote PHP file but that variable did not have that value in the including PHP file on the line just after the include statement. Did I miss-understand the PHP manual ?
    the include statement is proccessed before the php script is compiled,
    any file included, is basically copy and paste into the including script.

    file1.php
    PHP Code:
    <?php
    $var 
    'foo';
    ?>
    file2.php
    PHP Code:
    <?php
    include 'file1.php'
    echo $var// outputs foo
    ?>

  3. #3
    SitePoint Member
    Join Date
    Dec 2003
    Location
    USA
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gasolene
    the include statement is proccessed before the php script is compiled,
    any file included, is basically copy and paste into the including script.
    This is true when including a PHP file with a relative path (on the same server). But is it true when including a remote PHP file on another server ? Can't be as the included remote PHP file code will not be revealed to the including code.

    Seems to me that the including PHP script pauses as it invokes the remote script and resumes execution when the remote file finishes exection without any idea of what the remote script is.

  4. #4
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by salam
    This is true when including a PHP file with a relative path (on the same server). But is it true when including a remote PHP file on another server ? Can't be as the included remote PHP file code will not be revealed to the including code.
    No, because when you fetch a PHP file from another server, that server will processes it and will send out the output (not the PHP code) from the file.
    -- Jelena --

  5. #5
    SitePoint Member
    Join Date
    Dec 2003
    Location
    USA
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jelena
    No, because when you fetch a PHP file from another server, that server will processes it and will send out the output (not the PHP code) from the file.
    Where does it send output to ? To the user's browser ! Can I make that output be sent to the invoking PHP script ? From the PHP manual seems I can ... but I could not figure out how

    This is what the PHP manual states:
    ... unless the output of the remote file has valid PHP start and end tags (as with any local file). You can declare the needed variables within those tags and they will be introduced at whichever point the file was included.

  6. #6
    SitePoint Member
    Join Date
    Dec 2003
    Location
    USA
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You know what ... now I think that the remote PHP script always sends its output back to the invoking script and that in turn sends what it receives to the user's browser. Thus, what I need to try is putting the following statement in the remote PHP script:

    PHP Code:
     
    echo ("<?PHP $" . "remoteResult 'result-1' ?>");
    worked


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
  •