/    Sign up×
Community /Pin to ProfileBookmark

use <?php include ?> to call file on ANOther domain?

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 ?)

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyApr 02.2008 — First remove the space between include and the open bracket. If include doesn't work then, try fopen() and echo
Copy linkTweet thisAlerts:
@cconn64Apr 02.2008 — If they reside on the same server, you could always do this:
[CODE]<?php include_once("/var/www/complete path to other website") ?>[/CODE]

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.
Copy linkTweet thisAlerts:
@stephan_gerlachApr 02.2008 — If they are on different servers, you could also implement a little nice xmlrpc service.
Copy linkTweet thisAlerts:
@LouPhiauthorApr 02.2008 — 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
Copy linkTweet thisAlerts:
@bathurst_guyApr 02.2008 — [url=http://au.php.net/manual/en/function.fopen.php]fopen()[/url] and [url=http://au.php.net/manual/en/function.echo.php]echo[/url]
Copy linkTweet thisAlerts:
@NogDogApr 02.2008 — 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 [url=http://www.php.net/readfile]readfile[/url](). 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 [url=http://www.php.net/curl]cURL[/url] 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.
Copy linkTweet thisAlerts:
@cornbreadDec 26.2010 — 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.
×

Success!

Help @LouPhi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...