Solved

Include from other domain

Posted on 2011-02-14
11
293 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 108

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 108

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 108

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 108

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
The viewer will learn how to dynamically set the form action using jQuery.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now