Calling PHP script on a second server

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

    Calling PHP script on a second server

    The problem:
    I have script_1.php on a server. I'd like to call a script_2.php which
    is on a second server (remote one). Script_2.php is to do some
    processing on a second server and return results to script_1.php.
    Basing on the results script_1 goes on, using the results.

    Is a construction in script_1.php

    ...
    require("second server…/script_2.php");
    ...

    a good direction? (I need environment variables in script_1.php to be
    preserved after calling script_2.php). Or the problem needs quite
    different solution?

    Thanks in advance

    Marek Kotowski
    Warsaw
  • Erwin Moller

    #2
    Re: Calling PHP script on a second server

    Marek Kotowski wrote:
    [color=blue]
    > The problem:
    > I have script_1.php on a server. I'd like to call a script_2.php which
    > is on a second server (remote one). Script_2.php is to do some
    > processing on a second server and return results to script_1.php.
    > Basing on the results script_1 goes on, using the results.
    >
    > Is a construction in script_1.php
    >
    > ...
    > require("second serverÂ…/script_2.php");
    > ...
    >
    > a good direction? (I need environment variables in script_1.php to be
    > preserved after calling script_2.php). Or the problem needs quite
    > different solution?
    >
    > Thanks in advance
    >
    > Marek Kotowski
    > Warsaw[/color]

    Hi Marek,

    This is the kind of thing PHP rocks at. :-)

    lookup file at www.php.net

    (from script 1)
    $lines = file('http://www.marek2.com/myotherscript.p hp');

    'file' returns an array with results.
    So you let PHP wrap the URL and take care of the difficult stuff, so you can
    just enjoy the result easily ordered in $lines.

    Good luck!

    Regards,
    Erwin Moller

    PS: If you want to pass more info, just URLencode it:
    $lines =
    file('http://www.marek2.com/myotherscript.p hp?firstname=Ma rek&country=Pol and');


    Comment

    • Marek Kotowski

      #3
      Re: Calling PHP script on a second server

      Erwin Moller <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in message news:<42077293$ 0$28990$e4fe514 c@news.xs4all.n l>...[color=blue]
      > Hi Marek,
      >
      > This is the kind of thing PHP rocks at. :-)
      >
      > lookup file at www.php.net
      >
      > (from script 1)
      > $lines = file('http://www.marek2.com/myotherscript.p hp');
      >
      > 'file' returns an array with results.[/color]
      [...]

      Hi Erwin,

      It works. I get all html stuff, wchich is sent
      by a script, but - most important - I can include
      in it my own special markers with info I need.
      That's enough. I'll use the method.

      Many thanks :-)

      Marek Kotowski
      Warsaw

      Comment

      Working...