Page 1 of 1
access a php script on one server from another?
Posted: Fri Aug 25, 2006 4:45 pm
by robophobic
Here's what I'm needing to do:
I have a script on one server that lists the contents of a folder (images). The script works just fine locally and when called by a browser. I'm setting up a "master" server, on a different domain, and it needs access to that script.
So on the master server, the script needs to run and display the images from the remote server, by accessing the php file ON the remote server. I've tried an INCLUDE but that did nothing. I've also tried to "read" the remote file as if it were a text file, but again that did nothing.
Is there a way to do this?
Even if it's a kludgy work-around, I'd be happy!
Thanks in advance!
Posted: Fri Aug 25, 2006 4:53 pm
by pickle
I believe the only thing you could do is read the output of the PHP file. If the PHP file outputs a page of <img> tags, you could read that in, & parse out the filenames.
Posted: Fri Aug 25, 2006 5:02 pm
by robophobic
Thanks for your reply. How exactly would I do the reading? Opening it as if it were a text file, or including it? Or is there some other method that would work?
Posted: Fri Aug 25, 2006 5:10 pm
by pickle
Your system has to be set up for it, but you can use URL wrappers for some file opening functions. My favorite is
file(). If you can call:
Code: Select all
$file_contents = file('http://other.server.com/listing.php');
That'd be the way to do it.
file() generates an array with each file line being an array entry. You could loop through that & pull out the image names with some fancy regex

Posted: Fri Aug 25, 2006 5:26 pm
by RobertGonzalez
You might run into a permissions issue with though. I think I tried this once or twice and got spanked by the server for doing so.
You may want to look at
cURL as an alternative. But I could also be way off here.
Posted: Fri Aug 25, 2006 5:58 pm
by robophobic
Thanks so much for your quick replies, guys!
It's looking like there's something standing in the way of this working, and as i don't have access to the servers themselves to change the PHP settings, it looks like I'm going to have to take another path.
So here's what i'm thinking:
The main script, on the main site, checks a DB for a username and password, and the DB then returns the URL of that person's site. I was then going to have the script give them access to an admin page where they could edit text that is on their site. Since it's not looking like this is going to work with my servers' configs, I'm thinking now that I should instead have the main script check the DB, and then redirect the browser window to an admin script residing on the other server.
Only...
I HAVE NO IDEA HOW TO MAKE PHP REDIRECT.
dangit.
A search for "redirect" just brings up actual redirecting, not auto-loading another URL based on the results of an IF().
Maybe I'm searching for the wrong term?
Posted: Fri Aug 25, 2006 6:09 pm
by feyd
"header location" may give more useful results.
Posted: Fri Aug 25, 2006 6:46 pm
by RobertGonzalez
Or the PHP manual on the
header() function.
Posted: Fri Aug 25, 2006 7:22 pm
by bg
Sounds like something that could be achieved using SOAP. SOAP is basically a way for your php program to call functions from a remote script. It would require refactoring your code, and you would need to load the soap extension on both servers. This would be the most ideal solution to your problem based on what you're trying to do.
Another possibility, as someone had mentioned, would be to use cURL. This is also an extension, but would require no change to the original script, just your script trying to access the original. It basically turns your script into an HTTP client, grabbing the output (html) of whatever URL you are trying to access.