Solved

Include from other domain

Posted on 2011-02-14
11
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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