Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts

    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.


    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    335
    Thanks
    2
    Thanked 49 Times in 48 Posts
    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>
    Last edited by Redcoder; 01-07-2013 at 02:50 PM.

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    this can't be done, PHP is a server side language. have a look at PHP SOAP web services.

  • #4
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    335
    Thanks
    2
    Thanked 49 Times in 48 Posts
    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.

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    thats a terrible solution. SOAP is the proper way to share remote functionality.

  • #6
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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.

  • #7
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    335
    Thanks
    2
    Thanked 49 Times in 48 Posts
    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.
    Last edited by Redcoder; 01-07-2013 at 03:14 PM.

  • #8
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    what makes you think that SOAP can't be used to simply include content?

  • #9
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    335
    Thanks
    2
    Thanked 49 Times in 48 Posts
    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.
    Last edited by Redcoder; 01-07-2013 at 03:23 PM.

  • #10
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    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


    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #11
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    335
    Thanks
    2
    Thanked 49 Times in 48 Posts
    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.

  • #12
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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.

  • #13
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by Redcoder View Post
    Yes, Remote MySQL is just like normal except no localhost for hostname. You use something like...

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


    Since when was http used for all TCP based connections?

    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.
    I can't really think of anything to write here now...

  • #14
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    or IP address.

  • #15
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    335
    Thanks
    2
    Thanked 49 Times in 48 Posts
    Hahaha. Tangoforce. My bad. Must be the lack of sleep...no, not me. Haha


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •