471,319 Members | 1,632 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Including a .php file from another server?

I am trying to include a function in a .php file on a different server from
the main .php files.

I am using:

include_path=http://www.anotherserver.com/foldername;
include(http://www.anotherserver.com/foldern...letocall.inc);

The .inc file is php formatted. Variables are passed to it (not via GET or
POST though) and returned using return(variablenames, etc);

But for some reason it doesn't appear to work properly.

Am I correct in using the .inc extension?
Are the commands above correctly written?

Basically I am trying to use the fsockopen function in a .php file on
another server where I know it works and return the results to a server
where the fsockopen command doesn't work.

Any help or guidance would be greatly appreciated.
TIA
h
Sep 25 '05 #1
5 2093
hntgzr wrote:
I am trying to include a function in a .php file on a different server from
the main .php files.

I am using:

include_path=http://www.anotherserver.com/foldername;
include(http://www.anotherserver.com/foldern...letocall.inc);

The .inc file is php formatted. Variables are passed to it (not via GET or
POST though) and returned using return(variablenames, etc);

But for some reason it doesn't appear to work properly.

Am I correct in using the .inc extension?
Are the commands above correctly written?

Basically I am trying to use the fsockopen function in a .php file on
another server where I know it works and return the results to a server
where the fsockopen command doesn't work.

Any help or guidance would be greatly appreciated.
TIA
h


When you access your php file this way, it has already been parsed by
the web server. It's just like accessing it from your browser.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 25 '05 #2
>I am trying to include a function in a .php file on a different server from
the main .php files.
When you fetch a PHP file from a remote server, that server processes it
and sends out the OUTPUT (not the PHP code) from the file. I don't
know how Apache on the server you are trying to fetch from deals
with .inc files as opposed to .php files.

Here's an idea: why don't you COPY phpfiletocall.inc to the local
server and use it there?
include_path=http://www.anotherserver.com/foldername;
include(http://www.anotherserver.com/foldern...letocall.inc);

The .inc file is php formatted. Variables are passed to it (not via GET or
POST though) and returned using return(variablenames, etc);
If you were expecting to *RUN* phpfiletocall.inc on www.anotherserver.com,
how do you pass variables to it by other than via $_GET or $_POST?
But for some reason it doesn't appear to work properly.

Am I correct in using the .inc extension?
Are the commands above correctly written?

Basically I am trying to use the fsockopen function in a .php file on
another server where I know it works and return the results to a server
where the fsockopen command doesn't work.


If you are using 'include', you are fetching code from a server
where fsockopen will work (but you're not running it there) and
attempting to use it on a server where it won't work (but that's
where you're trying to make it work), if I understand your problem
correctly.

Gordon L. Burditt
Sep 25 '05 #3

"Gordon Burditt" <go***********@burditt.org> wrote in message
news:11************@corp.supernews.com...
I am trying to include a function in a .php file on a different server
from
the main .php files.


When you fetch a PHP file from a remote server, that server processes it
and sends out the OUTPUT (not the PHP code) from the file. I don't
know how Apache on the server you are trying to fetch from deals
with .inc files as opposed to .php files.

Here's an idea: why don't you COPY phpfiletocall.inc to the local
server and use it there?
include_path=http://www.anotherserver.com/foldername;
include(http://www.anotherserver.com/foldern...letocall.inc);

The .inc file is php formatted. Variables are passed to it (not via GET
or
POST though) and returned using return(variablenames, etc);


If you were expecting to *RUN* phpfiletocall.inc on www.anotherserver.com,
how do you pass variables to it by other than via $_GET or $_POST?
But for some reason it doesn't appear to work properly.

Am I correct in using the .inc extension?
Are the commands above correctly written?

Basically I am trying to use the fsockopen function in a .php file on
another server where I know it works and return the results to a server
where the fsockopen command doesn't work.


If you are using 'include', you are fetching code from a server
where fsockopen will work (but you're not running it there) and
attempting to use it on a server where it won't work (but that's
where you're trying to make it work), if I understand your problem
correctly.

Gordon L. Burditt


Thanks for the reply.

Yup, you understand my problem correctly :)

I am trying to run code on a server where fsockopen does work from the sites
local server where fsockopen doesn't work.

The code located on the remote server (i think that's the correct
terminology) is:

[This is the announce-connectable.inc file]
---------

<?

$sockres = @fsockopen($ip, $port, $errno, $errstr, 8);

if (!$sockres)
{
$connectable = "no";
// @fclose($sockres);
}

else
{
$connectable = "yes";
@fclose($sockres);
}

@return($ip, $port, $errno, $errstr);

?>

---------

The php file on the local server that's calling it is using:
include_path="http://www.anotherserver.com/folder";

include("http://www.anotherserver.com/folder/announce-connectable.inc");
Included in that file are the variables $ip and $port. $errno and $errstr
are not passed to the .inc file as they should always be null prior to be
returned.

Am I trying to do something that PHP can't do?

TIA
h
Sep 25 '05 #4

"Gordon Burditt" <go***********@burditt.org> wrote in message
news:11************@corp.supernews.com...
I am trying to include a function in a .php file on a different server
from
the main .php files.


When you fetch a PHP file from a remote server, that server processes it
and sends out the OUTPUT (not the PHP code) from the file. I don't
know how Apache on the server you are trying to fetch from deals
with .inc files as opposed to .php files.

Here's an idea: why don't you COPY phpfiletocall.inc to the local
server and use it there?


Because the command fsockopen doesn't work on the local server.
include_path=http://www.anotherserver.com/foldername;
include(http://www.anotherserver.com/foldern...letocall.inc);

The .inc file is php formatted. Variables are passed to it (not via GET
or
POST though) and returned using return(variablenames, etc);


If you were expecting to *RUN* phpfiletocall.inc on www.anotherserver.com,
how do you pass variables to it by other than via $_GET or $_POST?


I thought the variables would pass to it anyway. I'm not an expert in PHP
and go only by the guidance on php.net! I've not programmed since the late
80's, so I'm a little out of touch, lol!

If I pass the variables in the URL as ?ip=$ip&port=$port would that work?

As an alternative, I could try calling a function written in CGI, but again,
I am stumped as to how to call a CGI function from a PHP file and have the
results returned!

TIA
h
Sep 25 '05 #5
If you want to run the included code on your server (like access a db
or files on the including server with this included script) you could
try a non standard ext. so, try including
anotherserver.com/includedscript.blah. The disadvantage here is that
someone could access www.anotherserver.com/includedscript.blah and see
your code, so you cant have anything secret on it. You might work
around this by using .htaccess on anotherserver.com to allow this
script only from your including server...but, I really dont know the
ins and outs of doing that.

--
juglesh

Sep 25 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Nick Messick | last post: by
4 posts views Thread by Ralf Koms | last post: by
3 posts views Thread by Will Chamberlain | last post: by
1 post views Thread by Martin Mücke | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.