Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Include from other domain

Posted on 2011-02-14
11
Medium Priority
?
299 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
Independent Software Vendors: 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 111

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 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

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

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

721 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