Solved

Include from other domain

Posted on 2011-02-14
11
296 Views
Last Modified: 2012-05-11
Hi folks is there a way to access with include a file in another domain? I have two domains in different servers and I want it to be able to include a file from the other server, is this possible? If it is, how would I go about it?

Cheers!
0
Comment
Question by:doRodrigo
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 34893618
Are  you wanting the rendered version of the file or the actual file contents such as the php code?

0
 
LVL 6

Expert Comment

by:t-max
ID: 34893627
Hi!
Have a look here: http://us2.php.net/manual/en/features.remote-files.php
Hope this will help you out. Good luck doRodrigo!
0
 

Author Comment

by:doRodrigo
ID: 34893634
The file has a conditional if that checks the domain from which the script is being opened, and if it is a certain domain it gives a certain html and if it is from another it gives another html.

Cheers!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:t-max
ID: 34893676
That shouldn't be a problem. Once you know the domain from where the request is done, you can decide with the if what html file you need on the remote domain.
You can then "fopen" the html file from the second domain, and use it locally.
0
 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 34893678
Ok, so you just need to grab the rendered html - That makes is a lot easier.  

The php settings on the "remote" server will need allow_url_fopen enabled.  If it isn't you will have to go the cURL route or use other options such as fsockopen().

If allow_url_fopen is enabled this should work:

include "http://www.yoursite.net/included_file.php";

if the page that is calling the included file requires the file you may want to use the require() or require_once() functions: http://php.net/manual/en/function.require-once.php

If you need additional help troubleshooting, just let us know.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 34895982
Whether you can "include a file in another domain?" will depend on whether your hosting company allows it.  It should be very easy to test.  As long as you control both of the domains in question there is not much security to worry about.
0
 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 34896021
Ray is right about the host allowing it, that is why I previously mentioned:

 "The php settings on the "remote" server will need allow_url_fopen enabled.  If it isn't you will have to go the cURL route or use other options such as fsockopen()."

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 34896031
Some important information to read before you depend on this:

http://bugs.php.net/bug.php?id=47444
http://www.php.net/manual/en/filesystem.configuration.php

So you want to set the permission in your php.ini file -- it is not settable inside your script with a line like this:

ini_set('allow_url_include', TRUE); // DOES NOT WORK

The code snippet failed with this message. Warning: require_once() [function.require-once]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/websitet/public_html/RAY_temp_dorodrigo.php on line 5


<?php // RAY_temp_dorodrigo.php
error_reporting(E_ALL);
ini_set('allow_url_include', TRUE);
echo "Hello World from LAPRBass.com";
require_once('http://nationalpres.org/RAY_temp_dorodrigo.php');

Open in new window

0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 34896037
This version worked fine.
<?php // RAY_temp_dorodrigo.php
error_reporting(E_ALL);
echo "Hello World from LAPRBass.com";
echo file_get_contents('http://nationalpres.org/RAY_temp_dorodrigo.php');

Open in new window

0
 

Author Closing Comment

by:doRodrigo
ID: 34896054
Cheers Ray, as usual it worked!

Thanks a lot.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 34896559
Thanks for the points, and good luck with your project! ~Ray
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question