Reading string from remote page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JoelWhitehouse@gmail.com

    Reading string from remote page

    Hi! I want to write a script that will read a .php file on a remote
    server and print to the current page a portion of the text contained in
    the remote file. I am just wondering what the best method is for
    reading from a file in this case - the file is only a few bytes long.
    I've seen a tutorial or two that only tangentially addresses my
    problem, and even then each one has varied greatly as to which object
    they utilize.

    Any ideas to get me started?

    Many Thanks,

    -Joel

  • Richard Cornford

    #2
    Re: Reading string from remote page

    JoelWhitehouse@ gmail.com wrote:[color=blue]
    > Hi! I want to write a script that will read a .php file on a
    > remote server and print to the current page a portion of the
    > text contained in the remote file.[/color]

    If "remote server" means a server that is not in the same domain as (or
    a sub-domain of) the domain serving the page to the browser then normal
    browser security will prevent any client-side mechanism from accessing
    the content.
    [color=blue]
    > I am just wondering what the best method is for
    > reading from a file in this case - the file is only a
    > few bytes long.[/color]

    Your own server could make the request to the "remote server" and pass
    the result of request on, side-stepping the security restrictions.
    [color=blue]
    > I've seen a tutorial or two that only tangentially addresses
    > my problem, and even then each one has varied greatly as to
    > which object they utilize.
    >
    > Any ideas to get me started?[/color]

    Everything depends on what your are attempting to achieve, which is not
    the simple matter of reading the output form a PHP script but includes
    the context in which you want to do so and an explanation of why you
    want to do so.

    Richard.


    Comment

    • JoelWhitehouse@gmail.com

      #3
      Re: Reading string from remote page

      Richard,

      Thanks for your reply! I have the goal of serving dynamic content on
      pages from a sever (A) that can serve little more than javascript. I
      have a separate perl/php capable server (B) that I have written a few
      server side scripts for, but I haven't found a way to display the
      generated content on B through a page served by A. (The purpose is to
      augment the capabilities of a blog account on server A.)

      On A, I don't have the ability to make a request to B, parse the
      result, and pass the rest on, since A is not server side capable. I
      was hoping the process could be as simple as displaying pictures from a
      separate server with the tag:
      <IMG [...] src="http://www.remotedomai n.com/pic.jpg">.

      Following that model, I have already tried dynamically genereating a
      ".js" file and including it with the tag:
      <SCRIPT [...] src="http://www.myBserver.c om/generated.js">
      Unfortunately, my blog account has a server side parser which
      eliminates the src attribute of the SCRIPT tag if the src doesn't
      belong to one of 12 approved domains (for security reasons.)

      If I could use javascript to open a *text* file on a remote server,
      read in a string, and print it, I wouldn't be including remote .js
      files - I would just be displaying text from a remote site.

      If that won't work, is there any way I could do a direct text include,
      similar to the way I can use an IMG tag to display remote graphics?

      Thanks again!

      -Joel

      Comment

      • Dr Clue

        #4
        Re: Reading string from remote page

        JoelWhitehouse@ gmail.com wrote:[color=blue]
        > Hi! I want to write a script that will read a .php file on a remote
        > server and print to the current page a portion of the text contained in
        > the remote file.[/color]

        The only thing you have to do is circumvent the cross-domain security
        restriction in javascript.

        Javascript security restrictions require that the scripting
        and the data being acted upon be delivered from the same domain
        (www.yourserver.com)

        So what you need is a serverside cgi, servlet or similar
        socket capable tool to proxy the request. The serverside widget
        would take the result of the request and print it out as javascript
        or such, and since the cgi , servlet or whatever was located on your
        domain , javascript is happy.

        --
        --.
        --=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
        --=<> Internet Programming since 1994 <>=-- DHTML NSAPI TCP/IP
        --=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
        --=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
        --.

        Comment

        • JoelWhitehouse@gmail.com

          #5
          Re: Reading string from remote page

          Thanks guys, you've been a help! Havea great day!

          -Joel

          Dr Clue wrote:[color=blue]
          > JoelWhitehouse@ gmail.com wrote:[color=green]
          > > Hi! I want to write a script that will read a .php file on a remote
          > > server and print to the current page a portion of the text contained in
          > > the remote file.[/color]
          >
          > The only thing you have to do is circumvent the cross-domain security
          > restriction in javascript.
          >
          > Javascript security restrictions require that the scripting
          > and the data being acted upon be delivered from the same domain
          > (www.yourserver.com)
          >
          > So what you need is a serverside cgi, servlet or similar
          > socket capable tool to proxy the request. The serverside widget
          > would take the result of the request and print it out as javascript
          > or such, and since the cgi , servlet or whatever was located on your
          > domain , javascript is happy.
          >
          > --
          > --.
          > --=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
          > --=<> Internet Programming since 1994 <>=-- DHTML NSAPI TCP/IP
          > --=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
          > --=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
          > --.[/color]

          Comment

          Working...