Auriga Posted October 21, 2006 Share Posted October 21, 2006 Hi!I have two servers: Server A and Server B with a website. Server A contains some general useful code in php functions, which will be used in the website on Server B.Now, how can I include the functionality in a php file on Server A in the website on Server B?For example:[myfunctionfile.php on Server A]function MyFunction(myArgs) { return "this is a test" + myArgs;}[myWebPage.php on Server B]<?php include("http://www.servera.com/myfunctionfile.php"); print MyFunction("for server B");?>The above should print out on myWebPage.php:this is a test for server BI already tried to rename the myfunctionfile.php to myfunctionfile.php.inc, but that didn't work.Thanks in advance! Quote Link to comment Share on other sites More sharing options...
ksteuber Posted October 23, 2006 Share Posted October 23, 2006 I'm not real experienced in this, but I know that the way you are doing this cannot work for one reason.You are retrieving the evaluated php page, not the raw page.eg: include("http://www.servera.com/myfunctionfile.php"); includes the html page that you get when visiting the page on your browser, not the php textfile that your code is looking for.Now I have three ideas, and i don't know how well any of them work, since I have never tried them.1) You could rename myfunctionfile.php myfunctionfile.txt so that Apache doesn't try to execute it before sending it.Downfalls: I don't know if Webpage.php will be able to figure out that the php commands in a text file are php commands and not text, but i suspect it will work as long as you surround the commands with <?php ?> Also, this will have the unfortunate effect of making your php function file publicly available for veiwing, but if this doesn't bother you, go ahead.2) You could change the include functuion to say: require("ftp://username:password@www.servera.com/myfunctionfile.php");Downfalls: This will not work with versions of PHP prior to PHP 4.3.0 I don't know if it accepts FTP even after 4.3.03) If number 2 doesn't work, you could include something like this: (I have not actually tried this yet, and their might be some bugs)[code]$handle = fopen("temp.php", 'w');$conn_id = ftp_connect("ftp://www.servera.com/myfunctionfile.php");$login_result = ftp_login($conn_id, $YOURUSERNAME, $YOURPASSWORD);if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!"; exit; }if (!ftp_fget($conn_id, $handle, myfunctionfile.php, FTP_ASCII, 0)){ echo "Could not get myfunctionfile.php"; exit;}ftp_close($conn_id);fclose($handle);require("temp.php");unlink("temp.php");[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.