get return value from remotely executed script

Discussion in 'PHP' started by BrianR2, Nov 14, 2007.

  1. #1
    Hi, I'm trying to get a value from a remotely executed script (on another server). From what I've read, it should work as both servers are running php 4.4 and have allow_url_fopen "on" to do something like this:

    remote server (myfile.php):
    return 0;
    PHP:
    local server:
    $get_value = include("http://www.remoteserver.com/myfile.php");
    PHP:
    For some reason, I just keep getting the integer '1' (or bool TRUE) returned to $get_value from the call to include but when you have a return statement in the file you are calling with include(), it should give the value returned from that script.

    I can't access any variables that are set in the remote script and I can't run this script on the local server.

    Anyone know how to get this to work?

    Thanks.
     
    BrianR2, Nov 14, 2007 IP
  2. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #2
    after include statement call the function which return a value
    $get_value = include("http://www.remoteserver.com/myfile.php");
    $some_variable = functionCall($param);
    
    PHP:
    Well, I guess. Not sure about it
     
    greatlogix, Nov 14, 2007 IP
  3. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #3
    hi, i think including a file that resides on another server is not allowed its a surefire security risk, your best bet if you want to get a value from another server is through SOAP or RPC
     
    serialCoder, Nov 14, 2007 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Instead of using include, use file_get_contents.
     
    TwistMyArm, Nov 14, 2007 IP
    BrianR2 likes this.
  5. drunnells

    drunnells Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I agree with TwistMyArm, to read the remote data with file_get_contents(). However, to do that you should be printing/echoing the return data, not using "return" in myfile.php.

    So the remote myfile.php would look something like:

    <?php
    $returnValue = "0";
    print $returnValue;
    ?>
    PHP:
    And your local script could have something like:

    <?php
    $get_value = file_get_contents("http://www.remoteserver.com/myfile.php");
    ?>
    PHP:
     
    drunnells, Nov 14, 2007 IP
    BrianR2 likes this.
  6. BrianR2

    BrianR2 Guest

    Messages:
    734
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ah..cool! It works with file_get_contents(). I tried something like that earlier but I didn't think of file_get_contents() to retrieve the output.
    Thanks for the responses...green props.
     
    BrianR2, Nov 14, 2007 IP