User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 422,812 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,330 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 5013 | Replies: 4
Reply
Join Date: Sep 2006
Posts: 53
Reputation: mahe4us is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
mahe4us's Avatar
mahe4us mahe4us is offline Offline
Junior Poster in Training

connect one server from another server through script

  #1  
Nov 1st, 2006
Hi everyone,

Iam a nuubie to PHP. I have faced some problems in my project. I want to access a server(folder in server) through script run by another server. Its possible to access the files kept in one server through script run by another server. Please anyone help me. Its very useful to me if anyone provide answer for this.

Thanku..
Mahe4us
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2006
Posts: 53
Reputation: Barnz is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Barnz Barnz is offline Offline
Junior Poster in Training

Re: connect one server from another server through script

  #2  
Nov 1st, 2006
Originally Posted by mahe4us View Post
Hi everyone,

Iam a nuubie to PHP. I have faced some problems in my project. I want to access a server(folder in server) through script run by another server. Its possible to access the files kept in one server through script run by another server. Please anyone help me. Its very useful to me if anyone provide answer for this.

Thanku..
Mahe4us

Do you mean just a list of files? or will it need to include all the other methods for instance renaming files etc?
Reply With Quote  
Join Date: Sep 2006
Posts: 53
Reputation: mahe4us is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
mahe4us's Avatar
mahe4us mahe4us is offline Offline
Junior Poster in Training

Re: connect one server from another server through script

  #3  
Nov 1st, 2006
Hi Barnz,

Thanks you for your nice reply. I will tell clearly to you. suppose an image is placed in a folder in a different server. I want to access the image or copy the image from that server location to my server location dynamically. I think you can understand the above problem. Expecting your reply..
Thanks
Reply With Quote  
Join Date: Jan 2006
Posts: 53
Reputation: Barnz is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Barnz Barnz is offline Offline
Junior Poster in Training

Re: connect one server from another server through script

  #4  
Nov 1st, 2006
Originally Posted by mahe4us View Post
Hi Barnz,

Thanks you for your nice reply. I will tell clearly to you. suppose an image is placed in a folder in a different server. I want to access the image or copy the image from that server location to my server location dynamically. I think you can understand the above problem. Expecting your reply..
Thanks


hmmm, do you own the other server?

It may get tricky if you do cannot place a PHP script on the remote server (aswell as the local server etc).

However it may still be possible, but you may have to tell it which images to download etc.
Reply With Quote  
Join Date: Sep 2005
Posts: 689
Reputation: digital-ether has a spectacular aura about digital-ether has a spectacular aura about 
Rep Power: 6
Solved Threads: 41
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Help Re: connect one server from another server through script

  #5  
Nov 3rd, 2006
Originally Posted by mahe4us View Post
Hi Barnz,

Thanks you for your nice reply. I will tell clearly to you. suppose an image is placed in a folder in a different server. I want to access the image or copy the image from that server location to my server location dynamically. I think you can understand the above problem. Expecting your reply..
Thanks


If all you want is to copy an image you can do something like:

[PHP]$img_txt = file_get_contents('http://example.com/image.jpg');

$fp = fopen('/local/server/path/to/image/directory/', 'w');

fwrite($fp, $img_txt, strlen($img_txt));

fclose($fp);[/PHP]

But I believe what you want is a bit more than that.

What is really comes down to is what network you have in place between the two servers. If you just have HTTP then you'll have to access averything via HTTP with the HTTP stream functions: http://us2.php.net/stream

or you could use FTP.

You do not have any access to localserver functions on the remote server though unless you use something like SSH. (PHP can access an SSH stream and do what you want, but I don't the SSH protocol so I couldn't help you with that).

Ultimately if you own both server and wanted to write a php script that would act like an SSH for example, you'll be write a wrapper for functions you could do at the localhost, but have the commands sent over HTTP.

I believe thats what Barnz mentioned.

Its not too hard to do though. You can start off by looking at the phpshell project on sourceforge: http://sourceforge.net/projects/phpterm/

It shouldn't be had to write a wrapper for executing commands on the remote server, the hard part would be to keep it secure.

Simple Example:

On your local server:

[php]// wrapper for calling remote php functions on the remote server
function remote_php_call($function, $arguments = false, $auth = false) {

$arguments = serialize($arguments);
$function = serialize($function);

$result = file_get_contents($remove_server.'?func='.$function.'&args='.$arguments.'&auth='.$auth);

return unserialize($result);

}
[/php]

On your remote server:

[php]
function remote_php_server($function, $arguments = false) {

$arguments = unserialize($arguments);
$function = unserialize($function);
$result = call_user_function($function, $arguments);

return serialize($result);

}

// first make sure you AUTHENTICATE the remote server,
// otherwise you open a door for everyone to run abitrary commands on your php server

$function = $_GET['function'];
$arguments = $_GET['arguments'];

echo remote_php_server($function, $arguments);

[/php]

Off course this will only be limited to data that can be serialized and sent over HTTP. ie: you cannot use a resource handlers from functions like fopen(), mysql etc.

Another option is to use one of the webservices such as XMLRPC, or SOAP etc. These have a well defined protocol..
Last edited by digital-ether : Nov 3rd, 2006 at 4:24 am.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 10:03 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC