View Full Version : PHP Include()
ashben
January 20th, 2002, 00:08
Guys I have this query ..
I have two servers (say A and B) and I wish to include a PHP script on server A in a script on server B. So the main script on server B should have something like ..
Include("serverA.inc.php");
How do I do that? Any workarounds?
Any help will be great!
megapuzik
January 20th, 2002, 00:26
include("http://ww.bla.com/bla.php");
ashben
January 20th, 2002, 05:17
Thanks but it doesn't work.
I have a test variable in a.php (on Server A) as ..
$test = "test123";
While the calling script, b.php (on server B) has ..
include ("http://www.serverA.com/a.php");
echo $test;
And the output of the above script is blank.
Please help!
megapuzik
January 20th, 2002, 07:54
You cant parse vars with include ! this why...
try to move the var with a html form (method=post).
ashben
January 20th, 2002, 10:33
This approach does work if both the PHP files are on the same server. Unfortunately, the project architecture won't permit form-based submission.
niv
January 20th, 2002, 10:54
It doesn't have to be HTTP, but you'll have to remotely access either one of the files if they're on different servers, so you can probably do:
include("a.php"); # local
include("ftp://username:password@ftp.server.tld/path/to/file/b.php"); # remote
You cant parse vars with include ! this why...
try to move the var with a html form (method=post).
No, you can, and that's what PHP adopted from Perl:
include("$variable"); # calls a file whose URL or path is given through $variable
megapuzik
January 20th, 2002, 11:10
You mean that with perl, I can move vars from one server to other ??
niv
January 20th, 2002, 11:22
No, I mean you can have a path to a file in an include through the use of variables.
i.e.
$this = "a.file";
$path="/path/to/";
include("$this$path"); # will include /path/to/a.file
megapuzik
January 20th, 2002, 11:35
I think that you also do it with php....never tried it, but I think that you can...
niv
January 20th, 2002, 11:49
Originally posted by megapuzik
I think that you also do it with php....never tried it, but I think that you can...
Uhh...that was PHP. :rolleyes:
Perl scripts usually use require.
megapuzik
January 20th, 2002, 12:04
Originally posted by Hayama-kun
Uhh...that was PHP. :rolleyes:
Perl scripts usually use require.
:D :D read my Signature...
BTW...there is also a require in php.....
require("bla.php")
niv
January 20th, 2002, 12:12
Originally posted by megapuzik
BTW...there is also a require in php.....
require("bla.php")
Yes, and there's a require_once ;)
Ares
January 20th, 2002, 16:23
change
$test = "test123";
to
<?php
$test = "test123";
?>
and chmod to 777.
agent007
January 20th, 2002, 16:42
Originally posted by Ares
change
$test = "test123";
to
<?php
$test = "test123";
?>
and chmod to 777.
Err... I think he know's that if he knows a bit about PHP :p
Anyways, I wouldn't CHMOD to 777 unless you want everyone to be able to write to that file. 755 should do, I think. ;)
Dusty
January 20th, 2002, 17:13
No one's answered your question yet so I guess it's up to me to burst your bubble. What you're trying to do can't be done. Including an external file won't include the file's contents, rather just it's output (an output that would be nothing if the external file is just a list of variables). I guess you could try printing out the variables in the external file (for example, instead of "$var='whatever';" you'd have "print '$var=\'whatever\';';") for the local one, but I'm not even sure if that would work... probably wouldn't, but worth a shot.
ashben
January 20th, 2002, 23:03
Ok. here's the inference:
I can include a remote file. What I did was that I renamed the remote file to b.inc instead of b.php. This way it can be included on both the remote & local server. The new problem however is that b.inc is publicly downloadable (ie: not safe).
Any suggestions?
Dusty
January 20th, 2002, 23:08
That's essentially doing what I suggested, only you're just including a text file instead of a PHP file that prints out its script instead of executing it. I'm surprised it works, actually.
Here's what you could do: Rename it back to a .php file and do like I said with printing it out, then to the top add a little function that checks the referrer. If it's from a.php, then print out b.php, otherwise show nothing.
For a.php on the local server, just include the URL to b.php and force PHP to load it as it would a remote file.
ashben
January 21st, 2002, 00:32
Dusty:
Doing an explicit response like ie: echo "\$test = \"test123\";"; in a.php doesn't work either. It simply dumps the output as plain text rather than evaluating it as PHP code in b.php.
niv
January 21st, 2002, 00:42
The only way I see it working without it being world readable is through FTP.
Dusty
January 21st, 2002, 00:53
Yes... that doesn't work and your way (the one you mentioned in the other post, renaming it .inc) doesn't work for me either. As I suspected to begin with, it just isn't possible. Calling a remote file simply gets its output, it doesn't read it like it does a local file. You could do some workarounds to get the contents of a remote file, like using FTP as TPFKaN posted or writing a relay script on the remote server to feed information to a.php (or b.php or whichever is the local file), but in either scenario you couldn't include it without first saving it locally.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.