CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Include code from other server ? (http://www.codingforums.com/showthread.php?t=285402)

jeddi 01-07-2013 01:35 PM

Include code from other server ?
 
I am running 2 servers, one in the USA and one in the UK.

To make updates easier I want to ınclude php files from the USA server
in the php scripts of the UK server.

So I will have :

PHP Code:

<?php 
/*
*  index.php
*

*/
if(session_id() == ''){session_start();}

require_once(
"path-to-my-server/my_page.php");

then other stuff
?>

I did something similar between different virtual servers on the same
physical server by using a directory outside the local html directory.

EG using :
PHP Code:

require_once("/usr/local/mysites/head_cont.php"); 

But how would I do it between different servers ?

Javascript can pull code off any website and use it,
can php do a similar thing by using the url to get the php file
and then include it ?

Thanks.


.

Redcoder 01-07-2013 01:48 PM

Don't try it. Too big of a security risk.

But if you still want to push it on, take a look at:

http://httpd.apache.org/docs/2.0/mod/mod_access.html

Basically, you allow access using .htacess to a particular IP. (Never done it though)

Like:

Code:

<Directory *>
Order Deny,Allow
Deny from all
Allow from public_server.com 20.30.20.29
</Directory>


angst 01-07-2013 01:49 PM

this can't be done, PHP is a server side language. have a look at PHP SOAP web services.

Redcoder 01-07-2013 01:57 PM

Of course it can be done - if he sets the proper permissions and has the proper login and acess credentials for servers and script at each end.

Hell, he can even use FTP to get the local file and save it to a local folder. Using PHP and FTP with ftp_get(). Actually, it's easier to use ftp_get() then just call the newly saved file instead of sever configurations that will leave a huge gaping security hole.

angst 01-07-2013 02:00 PM

thats a terrible solution. SOAP is the proper way to share remote functionality.

angst 01-07-2013 02:02 PM

sure, lots of things are possible, he could even use Samba and create a long range share and mapping of the remote device, but again bad security, not the proper way to accomplish this and not what any experienced developer would call any elegant solution.

Redcoder 01-07-2013 02:08 PM

True, but the man doesn't want to interchange info, he wants to be able to include PHP code not available locally. SOAP won't do that for you mate. Elegant yes, but not the solution.

He wants a simple include('file_to_be_included.php').

And how is using PHP's FTP usage hacky and dirty? Its in the core of the PHP language and only needs 3 lines of code to implement such functionality.

angst 01-07-2013 02:17 PM

what makes you think that SOAP can't be used to simply include content?

Redcoder 01-07-2013 02:20 PM

Hmm...it actually can. Call another page that will read the.php files contents and then send it to the calling php file. Yeah. I must have just zoned out when you said:

Code:

"this can't be done, PHP is a server side language. have a look at PHP SOAP web services. "
Maybe there's a SOAP functionality thats more native than the one I mentioned. I don't use SOAP much....or at all in my line of work.

Hmpff. Haha. :)

jeddi 01-07-2013 02:56 PM

Is accessing a database on a different
physical server less of a problem ?

I usually just have something like:

PHP Code:

$host "localhost";
$user "boss"
$password "h8&k5sTmK9(s"
$database "mydb"

But if the MySQL db is on a different server,
I guess I need something other than "localhost".

What should I put in there in order to ensure access ?

Thanks


.

Redcoder 01-07-2013 03:01 PM

Yes, Remote MySQL is just like normal except no localhost for hostname. You use something like...

PHP Code:

$host "http://mysql.remotedomain.com"//its not always mysql.balhblah.com can be 2.remotedomain.com or http://remotedomain.com/mysql depends on hostname configured 

First, you need to make sure that your host provides remote MySQL acess. Most free hosts don't provide this.

You ussually have a hostname where you login fo phpmyadmin and such. Most hosts give this for use in scripts. e.g mysql.yourdomain.com . Just check with your host the subdomain or path for MySQL access.

angst 01-07-2013 03:02 PM

yes, if the ports are open on your firewall/router and your MySQL server is configured correctly to bind to any local address then yes, you can connect to the MySQL server from anywhere.

tangoforce 01-07-2013 04:29 PM

Quote:

Originally Posted by Redcoder (Post 1304615)
Yes, Remote MySQL is just like normal except no localhost for hostname. You use something like...

PHP Code:

$host "http://mysql.remotedomain.com"


:eek:

Since when was http used for all TCP based connections? :confused:

I've never known http be used for anything but webservers.

@Jeddi: What redcoder is saying is almost correct except that you don't use http:// on the address. You only use the actual hostname.

angst 01-07-2013 04:34 PM

or IP address.

Redcoder 01-07-2013 04:39 PM

:eek: Hahaha. Tangoforce. My bad. Must be the lack of sleep...no, not me. Haha :thumbsup:


All times are GMT +1. The time now is 04:40 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.