By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,129 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Reading string from remote page

P: n/a
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

Sep 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jo************@gmail.com wrote:
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.
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.
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.
Your own server could make the request to the "remote server" and pass
the result of request on, side-stepping the security restrictions.
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?


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.
Sep 25 '05 #2

P: n/a
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.remotedomain.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.com/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

Sep 25 '05 #3

P: n/a
Jo************@gmail.com wrote:
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.


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
--.
Sep 25 '05 #4

P: n/a
Thanks guys, you've been a help! Havea great day!

-Joel

Dr Clue wrote:
Jo************@gmail.com wrote:
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.


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
--.


Sep 26 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.