Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remote Scripts 1

Status
Not open for further replies.

Niclov

Programmer
Jun 28, 2001
45
0
0
CA
I'm trying to use PHP to run some CF code on a remote machine and have it display the output on a local webpage, where the PHP script resides. Does anyone know how to do this? I've found how to access remote machines, but not how to capture any output.
 
You have several ways to do this. If you simply want the complete results of the remote file to be displayed as if coming from your local server, you could use

Code:
readfile("[URL unfurl="true"]http://remoteserver.com/file.cfm?param=value&param2=value2_etc");[/URL]
(see
You could even use include(URL) to do this but that is pointless because the remote file would not be outputting PHP code to parse.

Or, If you want to get the remote contents of the file as a string variable, and do some other manipulation before presenting to the user, you could use something like

Code:
$remotefile = implode('',file("[URL unfurl="true"]http://remoteserver.com/file.cfm?param=value&param2=value2_etc"));[/URL]

Also, the next release of PHP should have an even easier syntax for this -- -------------------------------------------

"Now, this might cause some discomfort..."
(
 
Thanks Rycamor, but I need to do more than just read the file. There is coldfusion code hosted on the machine, and I need the output to be displayed on the page, since Cold Fusion in not installed on the same machine as this page.

Is this possible?
 
Read my post again:

1. I give you the way to transparently run the remote CF file (PHP acts as the "web browser" to grab the CF URL, and then passes that output to the requesting browser on the PHP site), with readfile().

2. I give you the way to capture the output from the remote CF URL, using implode(file(URL)). (PHP acts as the "web browser" to grab the CF URL, and then saves that output as a string variable in the local PHP script, so you can choose to pass the data to the requesting browser, or parse it with regular expressions, save it as a local file, or whatever you want to do).

To explain this more clearly: when PHP does a file operation on a file with " in the path, then that means PHP acts as a browser and gets the file (after parsing) from the remote webserver. So PHP would not grab the CF code, but the CF output. -------------------------------------------

"Now, this might cause some discomfort..."
(
 
Ah, I see how it works now, thank you very much. Tried the code on the page and it worked beutifully, saved me much grief :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top