Click to See Complete Forum and Search --> : use <?php include ?> to call file on ANOther domain?


LouPhi
04-02-2008, 05:29 AM
Hi

One of my customers has two websites - similar, but one is a more specialised version of the other (GPS products). The main website needs to display products which are mainly shown on the GPS product site - and rather than have 2 product pages the same (which would mean double the administration if/when any products needed changing or amending etc) I would like to have a php page on both sites, which calls the same .htm element into their page - showing the exact same table of products.

My question is this - can I use the <?php include ?> from the 'other' site to call the htm file which is actually situated on the 'other' domain?

I've tried using this exact script "<?php include ('http://domain.co.uk/filename.htm') ?>" but it doesn't work (I get a nasty "failed opening" message displaying on the page.

Any ideas - do I need to adjust the php in some way, or can it simply not be done??

Thanks for any help

LouPhi - forgot to mention, both domains in question reside on the same server..... if this helps :O)

bathurst_guy
04-02-2008, 06:16 AM
First remove the space between include and the open bracket. If include doesn't work then, try fopen() and echo

cconn64
04-02-2008, 07:27 AM
If they reside on the same server, you could always do this:
<?php include_once("/var/www/complete path to other website") ?>

Of course, it would probably be best to simply duplicate the file. Or, if it's on some flavor of Unix, create a link from one website's file to the other.

stephan.gerlach
04-02-2008, 07:33 AM
If they are on different servers, you could also implement a little nice xmlrpc service.

LouPhi
04-02-2008, 07:49 AM
Thanks for these responses... being a fairly non-techy person (fairly meaning VERY!) could you explain fully what is meant by "try fopen() and echo"? What would be the actual string to include, and where in the file?

I've tried removing the space as suggested by bathurst_guy and the 'include_once' method suggested by ccon64, but neither appeared to work??

Help!
LP

bathurst_guy
04-02-2008, 04:16 PM
fopen() (http://au.php.net/manual/en/function.fopen.php) and echo (http://au.php.net/manual/en/function.echo.php)

NogDog
04-02-2008, 04:29 PM
Unless you are accessing a file which you expect to include PHP source code to be processed in place in the calling file, you should not use include() (or require(), either). Instead use readfile (http://www.php.net/readfile)(). However, neither of these may work if the allow_url_fopen setting has been turned off (which is a common security measure). If that is the case, you may need to go the cURL (http://www.php.net/curl) route, or other options such as fsockopen().

In any case, showing us the exact error message(s) being received would likely help to determine what the exact nature of the problem is.

cornbread
12-26-2010, 04:31 PM
here's a way to debug your issue....
if this set works... your issue is in the script before the include...
also be sure the htm your calling has <?php?> tags

//view.php
<?php
include 'http://site.com/path/var.php(or in your case htm)';
if (isset($var))
{echo "$var. your file has been included";}
else
{echo "include has failed";}
?>

//var.php
<?php
// to test another file within this one (in reverse) include another variable from another address
$var = "variable sucess";
?>

you can alsways debug with small scripts to test certain things out... that's how im learning about all the small unsaid quarks dealing with php.